Skip to content

Instantly share code, notes, and snippets.

@carlosmcevilly
Last active December 19, 2015 13:09
Show Gist options
  • Save carlosmcevilly/5960329 to your computer and use it in GitHub Desktop.
Save carlosmcevilly/5960329 to your computer and use it in GitHub Desktop.
Script to create images for customizing UISwitch using ImageMagick
#!/usr/bin/perl
use strict;
use warnings;
# change these to your custom text values
my $ontext = "ON";
my $offtext = "OFF";
my $bgcolor = "none";
my $oncolor = "white";
my $offcolor = "\"#888888\"";
my $xoffset = -1;
my $yoffset = 4;
my $xshadowoffset = $xoffset;
my $yshadowoffset = $yoffset-1;
my $shadowcolor = "\"#444444\"";
my $fontspec = "-font Helvetica-Bold";
my $textspec = "-gravity center -stroke none $fontspec -strokewidth 0";
my $textsmall = "$textspec -pointsize 32";
my $textlarge = "$textspec -pointsize 64";
my $shadowspec_on = "-draw 'text $xshadowoffset,$yshadowoffset \"$ontext\"'";
my $shadowspec_off = "-draw 'text $xshadowoffset,$yshadowoffset \"$offtext\"'";
my $textspec_on = "-draw 'text $xoffset,$yoffset \"$ontext\"'";
my $textspec_off = "-draw 'text $xoffset,$yoffset \"$offtext\"'";
my $smallspec = "-size 77x27 xc:$bgcolor $textsmall";
my $largespec = "-size 154x52 xc:$bgcolor $textlarge";
my $onspec = "-fill $shadowcolor $shadowspec_on -fill $oncolor $textspec_on";
my $offspec = "-fill $shadowcolor $shadowspec_off -fill $offcolor $textspec_off";
my $smallcmd = "convert $largespec $onspec switch-on\@2x.png";
my $largecmd = "convert $smallspec $onspec switch-on.png";
print "running command: [$smallcmd]\n";
print `$smallcmd`;
print "running command: [$largecmd]\n";
print `$largecmd`;
$smallcmd = "convert $largespec $offspec switch-off\@2x.png";
$largecmd = "convert $smallspec $offspec switch-off.png";
print "running command: [$smallcmd]\n";
print `$smallcmd`;
print "running command: [$largecmd]\n";
print `$largecmd`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment