python 根据大图片生成各种规格图片 生成ios需要的各个规格的icon

PIL库要安装,直接使用pip安装:

pip install pillow

 

可能会报错,我python是3.x版本的,好像2.x版本的没有pip(需要单独安装)

 

3.x版本的安装如果报一堆错出来,它会提示需先更新pip版本(命令也提示出来了,照着输入执行即可):

`pip install --upgrade pip`

然后再安装插件: `pip install pillow`

 

python脚本代码:

#!/usr/bin/python
# -*- coding:utf-8 -*-

# 生成ios需要的各个规格的icon(通过1024*1024的图片)

from PIL import Image

infile = './expand_iOSicon_by1024/2.png'  # input('Please enter the image path: ')
outPath = './expand_iOSicon_by1024/2'  # input('Please enter the export path: ')
print('infile:' + infile)
img = Image.open(infile)
(w, h) = img.size
print('originW:' + str(w) + ',originH:' + str(h))

arr = [40, 60, 58, 87, 80, 120, 180]
for index in arr:
    newW = index
    newH = int(h * newW / w)
    print('h:{},newW:{},w:{},newH:{}'.format(h, newW, w, newH))
    outfile = outPath + '/' + 'Icon-' + str(index) + '.png'
    out = img.resize((newW, newH),
                     Image.ANTIALIAS)  # resize image with high-quality
    out.save(outfile)
    print('output file ' + 'Icon-' + str(index) + '.png...')

print('Export all ICONS finished...')

 

posted @ 2020-12-18 15:51  流失的痕迹  阅读(181)  评论(0编辑  收藏  举报