程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

python icon生成小工具

編輯:Python

在項目制作的過程中,有可能會出現一張圖片需要有不同的大小去適應不同的設備和位置時,手動去一個個制作比較麻煩,本人通過網上學習粗略敲了一段python腳本,可能有考慮不周之處還請指出。文底有下載鏈接

old_file = ""
new_file=""
new_format="RGB"
def create_image(pri_image):
for image in control["images"]:
if(image['filename'][0] == 'I'):
new_format = "RGB"
else:
new_format = "RGBA"
indexofx = find_last(image["size"],'x')
newsize = int(float(image["size"][:indexofx]) * int(image["scale"][0]))
pri_image.convert(new_format).resize((newsize, newsize), Image.ANTIALIAS).save(new_file + image["filename"])
def savecontents():
content = new_file+'Content.json'
json.dump(control,open(content,'w'),indent=4)
def get_file():
global old_file
old_file = raw_input("resource:")
print("old_file: %s" % old_file)
return Image.open(old_file)
def newfilepath():
global new_file
inx=find_last(old_file,'\\')
if(os.path.exists(old_file[:inx+1]+"AppIcon.appiconset") == False):
os.mkdir(old_file[:inx+1]+"AppIcon.appiconset")
new_file = old_file[:inx+1]+"AppIcon.appiconset\\"
print("new_file: %s" % new_file)
def outfilename():
for i in control["images"]:
print(i)
def find_last(string,str):
last_position = -1
while True:
position = string.find(str,last_position+1)
if position == -1:
return last_position
last_position=position
if __name__ == "__main__":
pri_image = get_file()
newfilepath()
create_image(pri_image)
savecontents()
print("finish")

icon生成工具使用說明:

1.使用:
一、雙擊icon生成工具腳本或拖拽到cmd回車
二、拖拽素材圖片到生成的窗口
三、生成對應壓縮包在素材文件下

2.可能出現的問題
一、沒有安裝python2
www.python.org/
二、No module named _curses
pip install windows-curses
沒有pip庫就安裝pip庫、也有可能pip沒有添加到系統變量
三、報錯The _imaging C module is not installed
沒有PIL庫或PIL庫與當前python不匹配
pip uninstall Pillow
pip install Pillow

格式備注:
1:1位像素,表示黑和白,但是存儲的時候每個像素存儲為8bit。二值化圖 \n
L:8位像素,表示黑和白。 灰度圖 \n
P:8位像素,使用調色板映射到其他模式。\n
RGB:3x8位像素,為真彩色。\n
RGBA:4x8位像素,有透明通道的真彩色。\n
CMYK:4x8位像素,顏色分離。\n
YCbCr:3x8位像素,彩色視頻格式。\n
I:32位整型像素。\n
F:32位浮點型像素。")

下載傳送門


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved