首先安裝所使用的庫 pillow亮隙,
pillow 是用來取代 PIL 的奕谭,
pip3 install pillow
安裝成功圖:
簡單的代碼:
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)處于同一目錄下瞧栗,運(yùn)行即可灯荧。
PS:
當(dāng)圖片的大小比要生成的圖片大小要小的話僵井,只會按圖片的大小生成出來陕截。
木子才~