Mobile app version of vmapp.org
Login or Join
Sue5673885

: How to resize every image on the blog to fit Google Page Speed test? I want to optimize the load time of a site that has more than 1200 pages. The site is built using WordPress and has

@Sue5673885

Posted in: #PageSpeed

I want to optimize the load time of a site that has more than 1200 pages. The site is built using WordPress and has lots of posts. I have improved the image sizes of the pages. What would be the fastest way to reduce the image sizes of the images in the blog posts? The idea I am getting is to use a resizing software on the /uploads folder.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Sue5673885

2 Comments

Sorted by latest first Latest Oldest Best

 

@Barnes591

If you need to resize all of the images, I think you should change the image sizes in WordPress or add a new one with the add_image_size() function.

You then need to regenerate all thumbnails/images. You can do this with this WordPress plugin: wordpress.org/plugins/regenerate-thumbnails/
At last you should use an image optimization plugin. I'd prefer TinyPNG but if you want something for free use EWWW Image Optimisation.

10% popularity Vote Up Vote Down


 

@Shakeerah822

Command-line tools

If you have a Linux machine and SSH access, try recursively batch processing all images on your site with some command-line utilities. These are very fast and free software. For these examples I assume an Ubuntu 16.04 system, but they also work well (with minor adjustments) on other versions and distributions.

First make a backup

Start by creating a directory 'backups' at the root of your user's /home:

mkdir /home/"$USER"/backups


Now back up your images directory. This command will create a compressed file of the directory with today's date in the file name:

tar czf /home/"$USER"/backups/site-photos-$(date '+%Y-%m-%d').tgz -C /PATH/TO/IMAGES/DIRECTORY/ .


(Don't forget the space at the end followed by a ".", and change "PATH/TO/IMAGES/DIRECTORY" to your actual images directory.)

To restore later if things go wrong use this command:

tar xvzf /home/"$USER"/backups/BACKUP-FILE-NAME.tgz -C /PATH/TO/IMAGES/DIRECTORY/


(Change "BACKUP-FILE-NAME.tgz" to match the actual file name, and change "PATH/TO/IMAGES/DIRECTORY" to your actual images directory.)

Image dimensions

Resizing image dimensions is easy with the 'mogrify' command included with the imagemagick package. Use the command apt install imagemagick to install it. To scale all JPEG images in a directory and its subdirectories to a maximum of 1000 by 1000 pixelstry this command:

cd /PATH/TO/IMAGES/DIRECTORY/
find -type f -name "*.jpg" -exec mogrify -resize 1000x1000 {} ;


If 1000 pixels is too large or small for you just change the '1000x1000' value above to 500x500 or whatever you like. If you have images with the .jpeg file extension instead of .jpg then edit that part of the command as well.

Image quality and metadata

You can quickly optimize JPEG image file size with the jpegoptim utility. Use the command apt install jpegoptim to install it. This command will recursively reduce the image quality to 80% and strip all image metadata.

cd /PATH/TO/IMAGES/DIRECTORY/
find -type f -name "*.jpg" -exec jpegoptim --max=80 --totals --strip-all {} ;


Other options

You can automate some of the above if you use the Apache HTTP Server with Google's Page Speed module. This goes way beyond just optimizing images, but you can download and install it with this one-liner (as root):

cd /tmp && wget dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_amd64.deb && dpkg -i mod-pagespeed-*.deb && apt-get -f install


For WordPress on Shared Hosting

For your WordPress site you can use an optimization plugin, such as this one for example. I don't have any experience with WordPress but searching their plugins site for "optimize images" returns many results. This is a good alternative if you are on shared hosting and cannot install software (or don't have SSH access).

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme