Blog Post

How to optimize images in Drupal

optimizing images drupal

After the development of the website, it is mandatory to give a user an overall excellent experience such as less loading time, or receiving the top rankings in search engine optimization. This can be completed by the performance optimization of the website. Optimized images are a vital component of website optimization.

Drupal has a built in feature that optimizes and compresses JPEG images. However, Drupal does not offer a feature that allows optimization of PNG format images that develop via Image style. Instead, in order to optimize PNG format of images, Drupal uses ImageAPI Otimize contributed model. Below is the URL of ImageAPI Optimize module:

https://www.drupal.org/project/imageapi_optimize

After downloading and enabling the ImageAPI Optimize module, navigate to admin/config/media/image-toolkit. You will be able to see this in the Drupal admin of your site. You can then proceed to select the ImageAPI Optimize radio button, and then click Save.

Following this, you should be sure to configure the ImageAPI Optimize Service settings.

You can use either commands RHEL or Debian based on Linux variants below to install image compressors on a server.

advpng (lossless):

Debian: apt-get install advancecomp

RHEL: yum install advancecomp

OptiPNG (lossless):

Debian: apt-get install optipng (ensure you are using a version 0.7.5 or higher)

RHEL: yum install optipng

Pngcrush (lossless):

Debian: apt-get install pngcrush (ensure you are using a version 0.7.5 or higher)

RHEL: yum install pngcrush

Pngout (lossless):

Debian: download binary archive and extract to /usr/local/bin

RHEL: download binary archive and extract to /usr/ bin

Pngquant (lossy):

Debian: apt-get install pngcrush (ensure you are using a version 0.7.5 or higher)

RHEL: yum install pngquant

Jpegoptim (lossless & lossy):

Debian: apt-get install jpegoptim

RHEL: yum install jpegoptim

Jpegtran (lossless):

Debian: apt-get install libjpeg-progs

RHEL: yum install libjpeg

Jfifremove (lossless):

It would need to be compiled after compilation copy it into your path:

wget http://lyncd.com/files/imgopt/jfifremove.c

gcc -o jfifremove jfifremove.c

mv jfifremove /usr /bin

After the installation of an image compressor, you can then add path of all the compressors in appropriate fields and conclude by saving the configuration.

We have completed the setup of ImageAPI Optimization. Now, we need to flush the existing image styles by using below Drush command:

drush image-flush

OR

You can install Image Style Flush module.

Leave a Reply

Your email address will not be published. Required fields are marked *

BACK TO TOP