在IOS开发,需要要生成各种大小ICON图片。美术导图虽然简单,但是效率低。
用脚本裁剪图片快而且不出错。
PY实现指定大小的ICON.
#encoding=utf-8
# -*- coding: utf-8 -*-
import os
import os.path
from PIL import Image
rootdir=os.path.abspath('.')
os.path.join(rootdir,'ios')
#type:输出图片类型(png, gif, jpeg...)
def ResizeImage(filein, fileout, width, height, type):
img = Image.open(filein)
out = img.resize((width, height),Image.ANTIALIAS) #resize image with high-quality
out.save(fileout, type)
a=[1024,512,180,167,152,144,120,114,100,87,80,76,72,60,58,57,50,40,29]
for i in a:
ResizeImage(rootdir+'/icon.png',rootdir+'/ios/'+str(i)+'.png',i,i,'png')