使用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)

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值