Creating high quality thumbnails for PDFs in Linux using Imagemagick

If you’ve been googling for a solution to this, you might have found the quality of your pdf thumbnails images created using imagemagick is less than what you’ve desired. There is a simple but not exactly straightforward reason for this. Imagemagick uses ghostscript to generate these thumbnails from pdfs, unless you specify the density before the filename, you may end up with poor quality thumbnails. I’ve used my resume to demonstrate.

# Create [a low quality] thumbnail image for the first page from a pdf
f="tyler.mulligan-resume-winter-2013.pdf"; convert $f[0] -quality 100 -resize 960x +adjoin $f-%02d.png
# Create [a high quality] thumbnail image for the first page from a pdf
f="tyler.mulligan-resume-winter-2013.pdf"; convert -density 300 $f[0] -quality 100 -resize 960x +adjoin $f-%02da.png

The difference in these thumbnails is minor but enough to drive a graphic designer insane. The font kerning is off and the shapes rasterize imperfectly.

Low Quality

tyler.mulligan-resume-winter-2013.pdf-00

High Qualitytyler.mulligan-resume-winter-2013.pdf-00a

I used the bracket page notation to define the first page of the pdf in the last two commands, filename.pdf[0] (zero index). It’s possible to do the entire PDF at once by removing it.

# Create high quality thumbnail images for a pdf
f="my.pdf"; convert -density 300 $f -quality 100 -resize 960x +adjoin $f-%02d.png

We can toss this in a for loop to perform the operation on a bunch:

# Create high quality thumbnail images from multiple pdfs
for f in *.pdf; do convert -density 300 $f -quality 100 -resize 960x +adjoin $f-%02d.png; done

If you’re still having issues with quality, you can play with the the -scale parameter, adding it after the -quality setting, i.e. “-scale @1500000″.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>