Using ImageMagick to create overlayed thumbnails
Gotta keep this short, but it’s been a while and I wanted to throw this on the blog before I forgot.
I have a client that wanted to have a PDF icon displayed over a thumbnail of a pdf document. These thumbnails are generated dynamically from documents that my client was uploading to a custom CMS site. The goal was to place the PDF icon over the thumbnail in the way Windows puts the arrow overlay on a shortcut except the pdf icon overlay needed to be placed on the bottom right and offset from the image. All I have to say is thank God for ImageMagick.
Using ImageMagick, I wr
ote a little bash shell script that creates a matte for the background, resizes the pdf and places it on the top left of the matte and then overlays the pdf icon on the bottom right. When it’s done, it deletes the matte. You can change sizes and background colors through the variables at the top of the script.
#!/bin/bash
appname=`which $0`
appdir=`dirname $appname`
backgroundcolor=white
compositesize='88x100'
coversize='69x90'
overlay=${appdir}'/adobe-overlay.png'
echo $overlay
convert -size $compositesize xc:$backgroundcolor background.jpg
composite -size $compositesize -compose atop -gravity NorthWest -resize $coversize $1.pdf background.jpg $1.jpg
composite -compose atop -gravity SouthEast $overlay $1.jpg $1.jpg
rm -f background.jpg
This script was written for ImageMagick 5.4.7-10 running on RedHat 9 (yes, it’s old). It only works for single
page pdfs and the overlay is assumed to exist in the same directory as the shell script. Contact me with any questions or comments.