fbpx
Skip to content

How to bulk optimize images faster on WordPress.

  • by

My friend was looking for a way to optimise over 1,000,000 images on his website. The website was massive, with many authors uploading thousands of images each month.

In general, it is always a good idea to optimise images before uploading them to WordPress, but if you haven’t done so already. Image optimization would become a time-consuming task. It takes a significant amount of time and effort to optimise each image individually or even via a bulk image optimization feature.

As I am a fan of shortpixel & how their service is extremely well, I suggested this exactly but the cost would be over $1000 for optimising such a large number of images, to say the least. (webp + optimization)

And the only option was to use the free plugins that are available. For example, the Ewww image optimization plugin could be of great help here.

Despite my thorough analysis, I observed that shortpixel outperforms the Ewww image optimizer plugin in terms of image optimization. Because the cost of this is quite high which is out-side of their budget, I recommended going with the free version instead for the time being.

Bulk optimize images

The next challenge was to optimise all of those images without spending an abnormally massive amount of time,

Optimizing images on wordpress means:

  • You will need to keep your browser window active. This is almost impossible for such number of images & how time consuming this can get.
  • You don’t know if the optimizer will fail to do due to timeouts or some other unknow reasons. This will become tedious task.

and he needed something that didn’t cost a lot of time. And it can be the same for a lot of more people, That’s why I thought writing an article specifically about how to optimise a large number of images faster.

And yes, I’ll also be including image optimization using shortpixel in this article as well. if anybody needs one such solution & willing to spend the money for better result.

Here is the simple strategy we will be using:

  • Download & Install optimization plugins.
  • Let optimizer run the bulk optimization in the background.

Requirments before proceeding:

  • Basic understanding of using terminal & wp-cli.
  • Should backup the website before doing anything else.

Optimizing bulk images via shortpixel.

Shortpixel allows you to optimize images on their cloud with better efficiency and significant better results. The good part is, shortpixel allows you to optimize images with simple command line.

Download shortpixel PHP SDK ZIP file.

wget https://github.com/short-pixel-optimizer/shortpixel-php/archive/master.zip

and extract it in your wordpress installation directory. Although it can be installed in other directory but let’s keep things easy & organized.

unzip master.zip

Navigate to the following path with

cd shortpixel-php-master/lib

Now we are ready to run the optimization task. you’ll need shortpixel license key to proceed. you can obtain this from the shortpixel account page.

and we would also need the wordpress media path location or you could simply use the following command if you’re not using any custom location for media path.

To run optimization, here is the command line.

php cmdShortpixelOptimize.php --apiKey=KeyHere --folder=/wp-content/uploads/ --speed=2
  • apiKey: Replace KeyHere with your own shortpixel license key.
  • folder: This is your wordpress media path.
  • speed: To avoid overload on server, keep optimization speed 2 seconds delay for each image optimization. If you’ve big server, you can skip this.

This command will scan all your media files and optimize images for you. You can also read their documentation on other parameter that could help you.

Optimizing bulk images via Ewww Image optimizer.

In case of optimizing using the free plugin, Ewww image optimizer. You’ll need to have the plugin installed in your wordpress instance. Go ahead & do it using the following command.

wp plugin install ewww-image-optimizer --activate

This command will install & activate the Ewww image optimizer for you. Before proceeding to image optimization, you can enable webp comvertion in the settings to convert your images to webp as well.

enable webp in ewww image optimizer settings
How to enable webp in ewww image optimizer settings

or You can also skip that. Now proceed with the simple following command to optimize images.

wp ewwwio optimize media 1 --no-prompt
  • 1: is your speed delay for each image optimization. You can set this to any number to delay if you’re on small server.
  • no-prompt: This will skip any prompt questions.

The optimization will generally takes a while depending on your number of images you have on your site. You can also make these commands runs in the background while you focus your time on other stuff. here is the handy guide to run tasks in the background.

I hope this article helped you one way or other to bulk optimize images faster. If you’ve any questions, let me know in the comment section.

Leave a Reply

Your email address will not be published.