I’ve been working on a tutorial for Nexuiz Ninjaz that requires a lot of screen shots. I’ve been utilizing the command line tool scrot to take screenshots on specific windows. These images however, are large pngs because the scrot date pattern wasn’t working properly when I tried to generate jpgs while repeating the same command. I went forward knowing I could find a way to batch compress these pngs later. Figuring I might as well “add a turbo while I’m under the hood”, I opted to both thumbnail the images (duh) and generate the forum thumbnail code (VROOOM).

So, to convert pngs to jpgs, I created a bash script which uses mogrify to convert, compress and thumbnail them and sed to assist in generating the forum code.

#!/bin/bash
#
# Convert pngs to jpgs, thumbnail them and generate forum code
# Created by Tyler Mulligan - www.doknowevil.net
 
condir=converted
if [ ! -d $condir ];then mkdir -p $condir;fi
pagename="http://www.nexuizninjaz.com/pics/howtos/map_link_a_ninja/"
 
# Convert to jpg and create thumbnails
echo -e "backing up originals...\n"
cp *.png originals
echo -e "converting to jpg...\n"
mogrify -format jpg *.png
echo -e "copying to converted directory...\n"
cp *.jpg $condir
echo -e "creating thumbnails...\n"
mogrify -resize 50% *.jpg
for file in *.jpg ; do mv $file `echo $file | sed 's/\(.*\.\)jpg/thumb_\1jpg/'` ; done
mv *.jpg $condir
echo -e "cleaning up\n"
rm *.png
 
# Generate forum code
for file in $condir/thumb_*.jpg ; do 
	tempname=`echo $file | sed 's/thumb_\(.*\)/\1/'`;
	echo "[url=${pagename}${tempname}][img]thumb_${tempname}[/img][/url]"
done

Future plans call for adding flags to support different image types, and including the ability to take screen shots and generate the forum code on a per screen shot basis.

Sorta Off Topic: I’ve taken a swing at frameworks be developing a new layer of organization on top of cfg files in nexuiz. I’ve thoroughly documented this scalable, fully customizable package I’ve dubbed the Ninja Pack for Nexuiz