AEM 6.3: Creating GIF renditions using Gifsicle in a workflow

2017-12-07

Creating GIF renditions seems like a simple task but I encountered some bumps along the way, let me show you how to do it!

AEM uses Imagemagick to create renditions for the usual file formats (png, jpg...) but it has a serious flow, creating renditions for the GIF file format is really slow.

Gifsicle to the rescue!

Gifsicle manipulates GIF image files. Depending on command line options, it can merge several GIFs into a GIF animation; explode an animation into its component frames; change individual frames in an animation; turn interlacing on and off; add transparency; add delays, disposals, and looping to animations; add and remove comments; flip and rotate; optimize animations for space; change images' colormaps; and other things.

The following command can be used to resize a gif (preserving aspect ratio):

1
gifsicle ${filename} --resize-width 300 > rendition-300.gif

${filename} is provided by the CommandLineProcess

The issue

AEM is using a Java ProcessBuilder behind the scenes to execute the commands but you can't include output redirection as part of the command (> resized.gif)

The solution

Copy the file before you resize it and use the --batch flag:

To modify GIF files in place, use the --batch option. With --batch, gifsicle will modify the files you specify instead of writing a new file to the standard output.

So now we have the following 2 commands:

1
cp ${filename} rendition-300.gif
1
gifsicle --batch rendition-300.gif --resize-width 300

This is how it could look in your workflow (update_asset):

This should allow you to quickly create renditions for your gifs. If you do have any questions, do not hesitate to contact me or leave a comment below.

Created by Jeroen Druwé