Jan 30, 2009

Nautilus-action : Generating thumbnails script


Still in my quest to find a smart way to generates thumbnails from a selected pictures I stumble on this nautilus-action script
Make thumbnails from selected images | GrumZ.Net

And then I pushed it a little further (code below) so it creates a thumbnail sub-directory and add a little blur effect (previously discovered in a previous post) -

Enough talk > here's the code :


#!/bin/bash
# ===========================================
# Thumb_export.sh
# ===========================================
# Script called by nautilus-action
# This script can handle multiple selection
# from various directories
# ===========================================
# REP = current directory path
# THB = thumbnail path and filename
# THB_SIZE = size of the thumbnail
# ===========================================
# version 0.02a
# Fri 30 Jan 2009 04:22:32 PM CET

THB_SIZE="184"

for f in "$@"; do
# extracting the current directory and create a thumbnail sub directory
REP=`dirname "$f"`"/thumbnail"
if `test -d $REP`; then echo "thumbnail dir already exists"; else mkdir $REP; fi
THB=`echo $REP`"/`basename $f`"
# now generates the thumbnail with
convert $f -thumbnail $THB_SIZE \( +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 \
$THB
done

xmessage "OK, it's done"

NB : I do not pretend to be a brilliant shell developer ; so be careful when using this code, the dozen of tests I performed with it (with multiple selection (across various directories), jpg, png, etc ...) worked, so I can say that nothing terrible (or funny) should happened.

But of course, if you're a shell wizard - I would totally appreciate your comment or help.

No comments:

Popular Posts