首先安装所使用的库 pillow,
pillow 是用来取代 PIL 的,
pip3 install pillow
安装成功图:
A866FFD7-2283-4BFB-8313-DBDEE909A579.png简单的代码:
from __future__ import print_function
import os, sys
from PIL import Image
imgNames = [((57,57),"icon.png"),
((114,114),"icon@2x.png"),
((171,171),"icon@3x.png"),
((20,20),"icon-20.png"),
((40,40),"icon-20@2x.png"),
((60,60),"icon-20@3x.png"),
((29,29),"icon-29.png"),
((58,58),"icon-29@2x.png"),
((87,87),"icon-29@3x.png"),
((40,40),"icon-40.png"),
((80,80),"icon-40@2x.png"),
((120,120),"icon-40@3x.png"),
((50,50),"icon-50.png"),
((60,60),"icon-60.png"),
((120,120),"icon-60@2x.png"),
((180,180),"icon-60@3x.png"),
((76,76),"icon-76.png"),
((152,152),"icon-76@2x.png"),
((228,228),"icon-76@3x.png"),
((83.5,83.5),"icon-83_5.png"),
((167,167),"icon-83_5@2x.png"),
((250.5,250.5),"icon-83_5@3x.png")]
i = 0
for i in range(len(imgNames)):
imt = Image.open("image.png")
size = imgNames[i][0]
#print size
name = imgNames[i][1]
#print name+type(name)
imt.thumbnail(size)
imt.save(name)
i = i+1
该脚本和图片(image.png)处于同一目录下,运行即可。
PS:
当图片的大小比要生成的图片大小要小的话,只会按图片的大小生成出来。
木子才~
网友评论