Skip to content

Instantly share code, notes, and snippets.

@warrenburton
Last active August 29, 2015 14:13
Show Gist options
  • Save warrenburton/164815f49577cc7f807d to your computer and use it in GitHub Desktop.
Save warrenburton/164815f49577cc7f807d to your computer and use it in GitHub Desktop.
Down samples a base png at 3x to 2x and 1x and outputs 3 UIKit style named files usage: spliticon.pl masterfile.png
#! /usr/bin/perl
#usage spliticon.pl masterfile.png
#e.g masterfile.png at 90*60
#outputs 3 files into subdir spliticons of cwd
#spliticons/masterfile.png at 30*20
#spliticons/masterfile@2x.png at 60*40
#spliticons/masterfile@3x.png at 90*60
use File::Basename;
use File::Copy;
$subdir = "spliticons";
mkdir $subdir;
$filename = $ARGV[0];
($name,$path,$suffix) = fileparse($filename,".png");
sub lastWord {
my @s = @_;
my @things = split(' ',$s[1]);
return $things[1];
}
$pixHeight = lastWord(`sips -g pixelHeight $filename`);
$pixWidth = lastWord(`sips -g pixelWidth $filename`);
$nextwidth = $pixWidth;
$nextheight = $pixHeight;
$nextname = $name."\@3x".$suffix;
copy($filename,"$subdir/$nextname");
`sips -z $nextwidth $nextheight $subdir/$nextname &>/dev/null`;
$nextwidth = $pixWidth*2/3;
$nextheight = $pixHeight*2/3;
$nextname = $name."\@2x".$suffix;
copy($filename,"$subdir/$nextname");
`sips -z $nextwidth $nextheight $subdir/$nextname &>/dev/null`;
$nextwidth = $pixWidth/3;
$nextheight = $pixHeight/3;
$nextname = $filename;
copy($filename,"$subdir/$nextname");
`sips -z $nextwidth $nextheight $subdir/$nextname &>/dev/null`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment