Python3 生成icon图标

首先安装所使用的库 pillow,
pillow 是用来取代 PIL 的,

pip3 install pillow

安装成功图:

Python3 生成icon图标_第1张图片
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),"[email protected]"),
            ((171,171),"[email protected]"),
            ((20,20),"icon-20.png"),
            ((40,40),"[email protected]"),
            ((60,60),"[email protected]"),
            ((29,29),"icon-29.png"),
            ((58,58),"[email protected]"),
            ((87,87),"[email protected]"),
            ((40,40),"icon-40.png"),
            ((80,80),"[email protected]"),
            ((120,120),"[email protected]"),
            ((50,50),"icon-50.png"),
            ((60,60),"icon-60.png"),
            ((120,120),"[email protected]"),
            ((180,180),"[email protected]"),
            ((76,76),"icon-76.png"),
            ((152,152),"[email protected]"),
            ((228,228),"[email protected]"),
            ((83.5,83.5),"icon-83_5.png"),
            ((167,167),"[email protected]"),
            ((250.5,250.5),"[email protected]")]

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:
当图片的大小比要生成的图片大小要小的话,只会按图片的大小生成出来。

木子才~

你可能感兴趣的:(Python3 生成icon图标)