Is it possible to compress or optimize images that are already uploaded to the server? What about a method to optimize the images on upload?


  1. Take all existing images, compress them, and then save them with the same file name and directory so that the image URLs are not broken.
  2. On upload of an image, optimize it so we don't have to repeat #1 above.

3 Answers 3


The common approach is not to modify the uploaded original image, but to calculate additional image variations and serve those to your visitors. All image styles created in /admin/config/media/image-styles are automatically compressed, using the settings form /admin/config/media/image-toolkit

  • this seems like the best solution without the need of a module. We set the JPEG quality to <90% in different scenarios it appears to compress the image down from about 3MB down to about <~512KB at times depending upon the size. Commented Dec 4, 2017 at 18:21

You're looking for https://www.drupal.org/project/imageapi_optimize. It uses image styles.


You could use something like imageMagick

Or depending on what kind of compression or optimisation you want to do you could go for a server side shell script or tools that handle the image processing. Run it as a cron job or something late at night.

You will likely need to install something like imageMagick on the server in any case.

  • imageMagick seems to work on images that are being uploaded so it meets goal 1, but not goal 2. Commented Dec 4, 2017 at 18:08
  • Wouldn't drush image-flush --all take care of this in drupal 8? Commented Sep 11, 2018 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.