How to compress images and PDF in Craft

Craft Image and PDF compression script upload

The Craft image and PDF compression is possible using a script. This script is compatible with all the servers that run PHP, all CMS, it's a standalone installation. It means that you just need to upload a folder of files on your server, then you can start to compress all images and PDF of this server.

The script can be downloaded here:

 

Note: Placing the files at the root of you Craft installation is always a good idea because you'll need to browse folders and subfolders after install, to select what is going to be compressed.

 

Then download + unzip the archive and drop the folder on your server.

craft-standalone-install

 

Run the image compression script installation

You can now call the folder path from your browser typing the URL: www.mywebsite.com/ImageRecycle-Standalone (default name). The install routine will be called, you need to define a password to secure folder access.

password-image-compression

 

Setup your password, it can be anything, nothing related to your Craft install. That should lead you to a success message.

setting-image-compression

 

Add API credentials to active Craft compression

First, you'll need to add your API key and secret available on My account > API and Quota menu. 

api-key-magento-compression

 

Setup the Craft image and PDF compression quality

Then you can select a type of compression per media type:

  • Best saving or Lossy: this is the best choice for a final usage, super compression yet not visible
  • Lossless: if you have plan to reuse images, you can use this setting, light compression but preserve all image data (like colors)
  • No compression: does not apply any compression on this media type

For more information about compression quality refer to this page: www.imagerecycle.com/images-and-pdf-optimization/images-and-pdf-compress

 

api-image-quality

 

Setup a cron task to make the compression automatic

A Cron task is a scheduled commands or tasks also known as “Cron Jobs" or "crontab".

A Cron URL is available in the script configuration to launch the Craft image and PDF optimization automatically. Depending of the Cron task setup, you can choose when you want launch the compression on your server. For an automatic compression you need to add this URL on your hosting Cpanel, sech for "Cron task" or "Crontab".

cron-url-auto-craft

Image Metadata, IPTC and Craft compression

The Metadata settings are also available to preserve some of the meta information of your images. For example you may want to preserve location information to use your images with a photo locator module?

image-metadata-save-from-optimization

 

Exclude / Include folders from Craft compression

Finally, you need to select where you want to run the optimization, which server folder will be compressed. This is usually at least the Craft image folders but that can be any folder listed (even from other CMS).

All your server folders under the ImageRecycle install are listed here, click on the name to deploy the folder tree. All new media added in those folders will be checked and listed in the next step for optimization.

craft-folders

 

Run the Craft image and PDF compression

Here we are, hit the top menu Images to list the optimizable media, if nothing is there hit the button SYNC ALL or try the filter field (top left).

image-listing

 

Then use optimize button to check everything is OK, you should be able to compress media and do a "revert to original". The revert option is available only during the media backup time (1 month).

image optimization launch

 

 

You can also launch a global optimization of your media. It's a background process, so you can close the window, the process will still be executed anyway.

background-optimization

 

And you can stop the compression process when you want.

stop-background-compression