Install Jpegoptim

If you haven’t jpegoptim installed on your environment execute the following in your terminal:

And if  you are running on Mac, make sure you have Homebrew install (

Optimize jpg

In your terminal, go to your project directory and execute the following command:

This will look and optimize each jpg image in your current directory and sub directories.


Most of the servers already has installed jpegtran. If that is your case, you can execute the following command

That will scan each file with the .jpg extension and optimize it by saving the changes with the same filename.



Install ImageMagick on your server.

If you are using OSX



If you want to resize a single image, you can do something like this

Resize only if size if current bigger than new size

NOTE: You may need a caret (^) rather than a backslash on Windows.

Convert to another image type

Change image quality


If you want to perform a bulk task on a directory, you can create a bash script like the following:

This will resize all of the images inside pub/media/attribute and force the width to be 350, respecting the aspect ratio.

Leave a comment