Last active
November 3, 2017 11:19
-
-
Save zummenix/3791111bf51e2ea80b19c6a188f4fd63 to your computer and use it in GitHub Desktop.
A script to resize an app icon for all sizes required by xcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from subprocess import call | |
import os | |
def format_name(size, scale): | |
return str(size) + "@" + str(scale) + "x" | |
def resize(size, scale): | |
name = format_name(size, scale) | |
file_name = name + ".png" | |
file_path = name + "/" + file_name | |
call(["mkdir", name]) | |
call(["cp", "icon.png", file_path]) | |
call(["sips", "-Z", str(int(size * scale)), file_path]) | |
call(["mv", file_path, "."]) | |
call(["rm", "-rf", name]) | |
def sizes(): | |
return [ | |
(20, 1), | |
(20, 2), | |
(20, 3), | |
(24, 2), | |
(27.5, 2), | |
(29, 1), | |
(29, 2), | |
(29, 3), | |
(40, 1), | |
(40, 2), | |
(40, 3), | |
(44, 2), | |
(50, 1), | |
(50, 2), | |
(57, 1), | |
(57, 2), | |
(60, 2), | |
(60, 3), | |
(72, 1), | |
(72, 2), | |
(76, 1), | |
(76, 2), | |
(83.5, 2), | |
(86, 2), | |
(98, 2), | |
(1024, 1) | |
] | |
# <icon height="57" src="res/icon/ios/icon-57.png" width="57" /> | |
def format_xml_name(size, scale): | |
d = str(int(size * scale)) | |
n = format_name(size, scale) | |
name = "<icon height=\"" + d + "\" src=\"res/icon/ios/" + n + ".png\" width=\"" + d + "\" />" | |
print(name) | |
for (size, scale) in sizes(): | |
resize(size, scale) | |
for (size, scale) in sizes(): | |
format_xml_name(size, scale) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment