使用Python实现的icon裁剪

使用python实现的icon裁剪

#!/usr/bin/python
#pic

import os,os.path
import Image

cur_dir=os.path.dirname(os.path.realpath(__file__))

def separateStr(symbol):
	temStr=''
	arr=[]
	for c in symbol:
		if c!='x':
			temStr+=c
		else:
			arr.append(temStr)
			temStr=''
	if len(temStr)>0:
		arr.append(temStr)
	return arr

goal_dir=cur_dir+'\icons'
if not os.path.exists(goal_dir):
	os.mkdir(goal_dir)

scr_file=cur_dir+'\icon.png'

infoDic={'Icon-29.png':'29x29','Icon-40.png':'40x40','Icon-50.png':'50x50','Icon-57.png':'57x57',
'Icon-58.png':'58x58','Icon-59.png':'58x58','Icon-72.png':'72x72','Icon-76.png':'76x76',
'Icon-80.png':'80x80','Icon-81.png':'80x80',
'Icon-87.png':'87x87','Icon-100.png':'100x100','Icon-114.png':'114x114','Icon-120.png':'120x120',
'Icon-144.png':'144x144','Icon-152.png':'152x152','Icon-180.png':'180x180','Icon-167.png':'167x167',
'icon.jpg':'1024x1024'}

img = Image.open(scr_file)
for key in infoDic.keys():
	arr=separateStr(infoDic[key])
	cropImg = img.resize((eval(arr[0]),eval(arr[1])),Image.ANTIALIAS)
	goal_file=goal_dir+'\\'+key
	cropImg.save(goal_file)

######android
androidDic={
	'/drawable-hdpi':'72x72',
	'/drawable-ldpi':'36x36',
	'/drawable-mdpi':'48x48',
	'/drawable-xhdpi':'96x96',
	'/drawable-xxhdpi':'144x144',
}
android_dir=cur_dir+'\icons'

for key in androidDic:
	if not os.path.exists(android_dir+key):
		os.mkdir(android_dir+key)
	cropImg = img.resize((eval(arr[0]),eval(arr[1])),Image.ANTIALIAS)
	goal_file=android_dir+key+'\\'+'icon.png'
	cropImg.save(goal_file)

 

你可能感兴趣的:(Python)