Jan 20, 2009

imagemagick script for thumbnails


Goodie, goodie - another try with imagemagick scripting - This time, the purpose is to generate thumbnail(s) with fixed width and with some little blur around the pictures ... just like the picture on the left.

Why ? because I'm using "phpwebgallery" and they recommend to generate the thumbnails externally before sending them over ftp to the website - to have the thumbnails in a sub-folder.

Anyway here's the script I made "export_thumb.sh"

#!/bin/sh
# export_thumb.sh
# ------------------------------------
# using imagemagick this script has to be launched from within
# the directory with your pictures (in jpg format) and it will
# exports thumb files 184 width in a sub directory named "thumb"

# create sub folder if it's not created already
if `test -d thumb`; then echo "thumb exists"; else mkdir thumb; fi

for i in *.jpg;
do
convert $i -thumbnail "184" \( +clone -blur 0x3 +level 20%,100% \) \
\( +clone -gamma 0 -shave 10x10 \
-bordercolor white -border 10x10 \) \
-composite \
\( +clone -gamma 0 -shave 10x10 \
-bordercolor white -border 1x1 \
-bordercolor black -border 9x9 \) \
-compose screen -composite \
thumb/$i
echo ".\c";
done
xmessage "OK ! script ended with Success";

There's a lot of other good examples on this page Thumbnails -- IM v6 Examples

No comments:

Popular Posts