in the process of making the project,There may be times when an image needs to be a different size to fit different devices and locations,It is more troublesome to do one by one manually,I roughly knocked a paragraph through online learningpython腳本,There may be ill-considerations, please point out.There is a download link at the bottom
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")
iconGenerate tool instructions:
1.使用:
一、雙擊iconGenerate tool scripts or drag and dropcmd回車
二、Drag and drop stock images to the generated window
三、The corresponding compressed package is generated under the material file
2.可能出現的問題
一、沒有安裝python2
www.python.org/
二、No module named _curses
pip install windows-curses
沒有piplibrary is installedpip庫、也有可能pipNot added to system variables
三、報錯The _imaging C module is not installed
沒有PIL庫或PILlibrary with currentpython不匹配
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位浮點型像素.")
下載傳送門