User:BarracudaATA/Scripts

Some scripts I've wrote to automate repetitive tasks when working on Minepedia.

Sprite Splitter
A shell script to extract all 16x16 sprites from items.png with ImageMagick:

 input=$1 output=$2
 * 1) !/bin/sh

if [ ! -d $output ]; then mkdir $output fi
 * 1) create output dir

convert -crop 16x16 +repage $input $output/%03d.png
 * 1) extract all sprites from items.png to 16x16 images

find $output -size -280c -delete
 * 1) delete empty sprites

Usage: extract.sh

Sprite Upscaler
A shell script to scale up all sprites in a folder to 150x150 with ImageMagick:

 input=$1 output=$2
 * 1) !/bin/sh

if [ ! -d $output ]; then mkdir $output fi
 * 1) create output dir

for x in `ls $input/*.png`; do	outfile=$output/`basename $x` # trim transparent pixels, then upscale and extent to 150x150 convert +set date:create +set date:modify -trim -sample 150x150 -gravity center -background transparent -extent 150x150 $x $outfile # optional: optimize with optipng optipng -o 5 $outfile > /dev/null echo "Processed $x"; done

Usage: upscale.sh

Pixel to SVG converter
A Perl script to convert small 8-bit PNG images into SVG vector images. Requires Perl GD library.


 * 1) !/usr/bin/perl

use strict; use GD;

if (!defined($ARGV[0])) { die "Usage: pixelvector.pl \n" };

my $imageFile = $ARGV[0];

my $image = GD::Image->newFromPng($imageFile); my $alpha = $image->transparent; my $pixelScale = 10; my $sourceWidth = $image->width; my $sourceHeight = $image->height; my $destWidth = $sourceWidth * $pixelScale; my $destHeight = $sourceHeight * $pixelScale;

my $viewBox = "0 0 $destWidth $destHeight";

print ' '."\n";

for (my $i = 0; $i < $sourceWidth; $i++) { for (my $j = 0; $j < $sourceHeight; $j++) { my $color = $image->getPixel($i, $j); # skip transparent pixels if ($color == $alpha) { next; }       my ($r,$g,$b) = $image->rgb($color); my $rgbHex = sprintf("%02x%02x%02x", $r, $g, $b); my $x = $i * $pixelScale; my $y = $j * $pixelScale; print ''."\n"; } }

print ' '."\n";