Skip to content

Instantly share code, notes, and snippets.

@simoncozens
Last active August 29, 2015 14:00
Show Gist options
  • Save simoncozens/70ac7c1122324f7cb4b0 to your computer and use it in GitHub Desktop.
Save simoncozens/70ac7c1122324f7cb4b0 to your computer and use it in GitHub Desktop.
PhoneGap Icon Maker - put this into .cordova/hooks/after_prepare/
#!/bin/perl
use strict;
my $base = shift @ARGV;
my $splash = "splash.ai";
my $icon = "icon.ai";
my @formats = (
[qw/ splash ios Default-Landscape@2x~ipad.png 1496 2048 /],
[qw/ splash ios Default-Landscape~ipad.png 748 1024 /],
[qw/ splash ios Default-Portrait@2x~ipad.png 2008 153 /],
[qw/ splash ios Default-Portrait~ipad.png 1004 768 /],
[qw/ splash ios Default@2x~iphone.png 960 640 /],
[qw/ splash ios Default~iphone.png 480 320 /],
[qw/ splash ios Default-568h@2x~iphone.png 1136 640 /],
[qw/ icons ios icon-40.png 40 40, /],
[qw/ icons ios [email protected] 80 80, /],
[qw/ icons ios icon-50.png 50 50, /],
[qw/ icons ios [email protected] 100 100, /],
[qw/ icons ios icon-60.png 60 60, /],
[qw/ icons ios [email protected] 120 120, /],
[qw/ icons ios icon-72.png 72 72, /],
[qw/ icons ios [email protected] 144 144, /],
[qw/ icons ios icon-76.png 76 76, /],
[qw/ icons ios [email protected] 152 152, /],
[qw/ icons ios icon-small.png 29 29, /],
[qw/ icons ios [email protected] 58 58, /],
[qw/ icons ios icon.png 57 57, /],
[qw/ icons ios [email protected] 114 114, /],
);
my %resources_dir = (
ios => sub {
my $which = shift;
my ($build) = glob("platforms/ios/*/resources/");
return "$build/$which/";
}
);
chdir $base;
if (!-r $splash) { die "Couldn't open splash file '$splash': $!\n"; }
if (!-r $icon) { die "Couldn't open icon file '$icon': $!\n"; }
my %platforms = map {$_ => 1} split /\s*,\s*/, $ENV{CORDOVA_PLATFORMS};
for (@formats) {
my ($which, $platform, $name, $h, $w) = @$_;
next unless $platforms{$platform}; # Only build for platforms we care about
my $path = $resources_dir{$platform}->($which)."/".$name;
my $source = ($which eq "splash" ? $splash : $icon);
if (-e $path and -M $source > -M $path) {
print "$path exists and is newer than source, skipping.\n"; next;
}
my @cmd = qw/ sips -s format png/;
if ($h > $w) { push @cmd, "--resampleHeight", $h; }
else { push @cmd, "--resampleWidth", $w; }
#sips -s format png --resampleHeight 1024 -c 1004 768 $1 --out Default~ipad.png
system(@cmd);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment