Thursday, October 15, 2009

Creating Thumbnails on Command Line

Image Magick is a great free image processing tool to do batch conversions. Many hosting companies running Linux servers will offer it by default. It will empower your website to create thumbnails and rescale images on the go (given your web-code utilizes it). For a full description click here

In this posting we want to explain how to create thumbnails (one by one or in batch)



  1. Install Image magic:sudo aptitude install imagemagick
  2. Create a thumbnail with given width: (example 100 pixels)convert -thumbnail 100 img.png tn_img.png
  3. Create a thumbnail with given height: (example 100 pixels)convert -thumbnail x100 img.png tn_img.png
  4. Creating thumbnails in batch with single command line

    find . -name \*.jpg -exec convert -thumbnail x100 {} th_{} \;

    or

    f
    ind . -name \*.jpg -exec convert {} -resize 25% th_{} \;
  5. creating a smal shell script to create thumbnails in batch. #!/bin/bash
    FILES="$@"
    for i in $FILES
    doecho "Processing Image $i ..."
    /usr/bin/convert
    -thumbnail 100 $i tn_$i
    done


Other ways of creating thumbnails involves scaling to a percentage of the original, and it usually creates smaller files, but you don't have control of the width . Height, unless all source images are the same size and aspect ratio.

No comments:

Post a Comment

Please be courteous, even if you do not share the same view.