使用python自动生成iOS各尺寸规格icon(基于一张1024大图),代码如下:
import PIL.Image imgNames = [((72,72),"icon-72.png"),((40,40),"icon-40.png"),((80,80),"[email protected]"),((50,50),"icon-50.png"),((100,100),"[email protected]"),((60,60),"icon-60.png"),((120,120),"[email protected]"),((180,180),"[email protected]"),((72,72),"icon-72.png"),((114,114),"[email protected]"),((152,152),"[email protected]"),((76,76),"icon-76.png"),((58,58),"[email protected]"),((29,29),"icon-small.png"),((57,57),"icon.png"),((114,114),"[email protected]")] im = PIL.Image.open("1024.png") i = 0 for i in range(len(imgNames)): imt = im size = imgNames[i][0] #print size name = imgNames[i][1] #print name+type(name) imt_r = imt.resize(size,PIL.Image.LANCZOS) imt_r.save(name) i = i+1
mac内置python环境(可能不包含PIL库,需下载),使用终端相关命令即可生成:
1.cd至1024图所在目录,将以上代码在相同目录下用vi保存为**.py
2.python **.py即可
3.其他尺寸需求,可自由在imgNames中修改
时间: 2024-10-05 14:54:42