Is there a better way?
Posted: 2011-09-25T19:22:43-07:00
So I've written a small shell script to batch caption/title a directory of images with a 20px bar on the top and include copyright info in a 20px bar on the bottom. What I'm wondering is if there is a better way to do it, or if my script can be leaner or more efficient. This was my first real attempt at using ImageMagick to work with my files in a batched manner, so I'm quite pleased that I got everything to do what I wanted - but now I want it better. Anyone able to offer suggestions to improve this? Or should I just leave it alone since it already works...
My script:
The format of filelist.txt that is read in:
Sample of the output: http://postimage.org/image/2atmlbbxg/
My script:
Code: Select all
cat ~/directory/filelist.txt |
while read filename text
do
# path to images
cpath="/home/user/path/to/images/";
# file extension
pext=".png";
# determines image width
width=`identify -format %w "${filename}${pext}"`;
# font to use for captioning
font="/usr/share/fonts/truetype/ttf-larabie-deco/cranberr.ttf";
#font size
pointsize="18";
# height of top/bottom caption bars
height="20";
# header text position
toppos="NorthWest";
# footer text position
botpos="SouthEast";
# static footer text to write
footer="Copyright 2011 Me";
# write the header caption from text file
convert -background black -font "${font}" -pointsize "${pointsize}" -fill white -gravity "${toppos}" -size "${width}x${height}" caption:" ${filename}: ${text}" ${cpath}${filename}${pext} +swap -gravity "${toppos}" -composite ${cpath}${filename}${pext}
#write the footer caption
convert -background black -font "${font}" -pointsize "${pointsize}" -fill white -gravity "${botpos}" -size "${width}x${height}" caption:"${footer} " ${cpath}${filename}${pext} +swap -gravity "${botpos}" -composite ${cpath}${filename}${pext}
done
Code: Select all
20110924 Hello World
20110925 Goodbye World
20110926 etc, etc.