Skip to content

Instantly share code, notes, and snippets.

@gibtang
Created June 2, 2013 15:16
Show Gist options
  • Save gibtang/5693814 to your computer and use it in GitHub Desktop.
Save gibtang/5693814 to your computer and use it in GitHub Desktop.
PHP script to auto create all the various iOS icons based on only 1 image. This requires ImageMagick to run http://www.imagemagick.org/script/index.php
<?php
$filename = $argv[1];//get the command line argument which is supposed to be the png filename
echo "Going to iconize \"$filename\"\n";
class imgFile
{
public $fileName;
public $size;
public function __construct($fileName, $size)
{
$this->fileName = $fileName;
$this->size = $size;
}
}
$imgArray = array(
new imgFile("Icon-72.png","72x72"),
new imgFile("Icon-Small-50.png","50x50"),
new imgFile("Icon-Small.png","29x29"),
new imgFile("[email protected]","58x58"),
new imgFile("Icon.png","57x57"),
new imgFile("[email protected]","114x114")
);
$dest = "BugMath2/Resources/";//This is the path of where your iOS icon files are to reside
foreach ($imgArray as $img)
{
//echo "$img->fileName $img->size\n";
$size = $img->size;
$fileName = $img->fileName;
$str = "\nCreating $size size of icon";
echo $str;
$response = shell_exec("convert $filename -resize $size $fileName");
if (is_null($response) == false)
exit("\nError at creating icon of $size");
else
echo "\nSuccess in creating icon of $size";
echo "\nCopying $fileName over to $dest";
shell_exec("cp $fileName $dest");
echo "\n========";
}
?>
@gibtang
Copy link
Author

gibtang commented Jun 2, 2013

To use, just type "php createIcon.php someimage.png" and just sit back and grab a beer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment