Performing Image Tiling Operations ImageMagick

Written by James McDonald

March 3, 2011

I just had the need to take a GIMP XCF file and create several different types of output images from it:

  • PNG File
  • JPEG File
  • Resize to thumbnail in JPEG format
  • 2×2 Tiled PNG with black and white borders

Using the Imagemagick and xcftools you can do it all via the command line with some simple scripting

In the past I have done the Image processing in multiple steps, creating different images for each step and then removing the intermediate images at the end, but the ImageMagick convert utility can do it all in one hit.

#!/bin/bash

echo Script recursively converts all xcf files
echo to PNG, JPG, tiled PNG \& thumbnail jpg
echo -n Do you wish to continue? \[Y\|n\]
read x
case $x in
	
	n|N)	
		echo No Pressed Aborting
		exit 0
		;;
	y|Y|*)
		echo OK
		;;
esac

# tell find to do a case insentive match for *.xcf *.XCF
FILES=`find -type f -iname \*.xcf | sort`

for i in $FILES
do 

	XCF=`basename $i

        # this is the filename without the extension
        # e.g sample.png returns sample
        SANS_EXT=`basename $XCF | sed -E 's/\.[a-z]{3}//g'

        # this is me doing it the hardway for each extension type
	PNG=`echo $i|sed s/\.xcf/\.png/`
	JPG=`echo $i|sed s/\.xcf/\.jpg/`
	MAP=`echo $XCF| sed s/\.xcf//`
	THUMB=`echo $JPG|sed s/\.jpg/-thumb\.jpg/`

	echo Converting $XCF to PNG
	xcf2png $i > $PNG
	echo Converting PNG to JPG
	convert -quality 100 $PNG $JPG
	echo Making thumbnail
        # a 250 pixel thumbnail image
	convert -resize 250x250 $JPG $THUMB

	echo Creating Tiled Image
	FILE=`echo $PNG | sed -e 's/.png//g'`
	
	
		convert $PNG -bordercolor black -border 2 \
			-bordercolor white -border 20 \
			-bordercolor black -border 1 \
			\( +clone \) +append \( +clone \) -append $FILE-tiled.png



done

This:

Becomes:

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

You May Also Like…

How to Research a CPU Upgrade

How to Research a CPU Upgrade

Upgrade Time! Doing a lot of VMWare Workstation virtualization to create labs for self-study and training. Finding...