python自動(dòng)化生成IOS的圖標(biāo)
本文實(shí)例為大家分享了python自動(dòng)化生成IOS的圖標(biāo),供大家參考,具體內(nèi)容如下
每次上架之前都要生成十幾個(gè)圖片感覺(jué)無(wú)聊麻煩,考慮使用腳本處理
腳本使用python 和一部分shell 處理的,python部分主要是使用PIL庫(kù)處理圖片,和調(diào)用shell腳本,shell 主要是操作文件
#coding=utf-8
import os ,threading
from PIL import Image
import subprocess
import json
class ImgManager(object):
thread_lock = threading.Lock()
@classmethod
def sharedinstance(cls):
with ImgManager.thread_lock:
if not hasattr(ImgManager,"instance"):
ImgManager.instance = ImgManager()
return ImgManager.instance
# 運(yùn)行shell命令
def runshellCMD(self,cmd,dsr):
progress = subprocess.Popen(cmd,shell=True)
progress.wait()
result = progress.returncode
if result !=0:
print("%s失敗"%(dsr))
else:
print("%s成功"%(dsr))
#創(chuàng)建圖片
def createImg(self,model):
path = '%s/AppStore.png'%(os.getcwd())
currentPath = "%s/Images/%s"%(os.getcwd(),model.filename)
print(currentPath)
im = Image.open(path,'r')
# w,h=im.size
# print("%s,%s"%(str(w),str(h)))
#
im.thumbnail((float(model.get_wh()),float(model.get_wh())))
if model.filename.endswith('.png'):
im.save("%s" % (currentPath),"png")
else:
# self.runshellCMD("sudo cp %s %s" % (path, currentPath), "拷貝")
self.addTransparency(im)
im.save("%s" % (currentPath), "jpeg")
# r, g, b, alpha = im.split()
# print("%s"%(str(im.split()[0])))
#修改透明度
def addTransparency(img, factor=0.0):
img = img.convert('RGBA')
img_blender = Image.new('RGBA', img.size, (0, 0, 256, 256))
img = Image.blend(img_blender, img, factor)
return img
#解析Contents.json,這個(gè)文件每一個(gè)Images.xcassets 的AppIcon文件夾都有,直接復(fù)用就可以了
def handle_icon_images(self):
jsonpath = os.getcwd() +"/Contents.json"
if not os.path.exists(jsonpath):
print("Contents.json path not exite")
return
with open(jsonpath,'r') as f:
jsonstr = f.read()
modle = json.loads(jsonstr)
arrs = modle['images']
# print(arrs)
icon_models=[]
for obj in arrs:
size=obj["size"]
idiom=obj["idiom"]
filename=obj["filename"]
scale=obj["scale"]
icom =iconImg(size=size,idiom=idiom,filename=filename,scale=scale)
# icon_models.append(icom)
self.createImg(icom)
"""
"size" : "29x29",
"idiom" : "iphone",
"filename" : "Icon-Small@3x.png",
"scale" : "3x"
"""
#json 數(shù)據(jù)里面有效數(shù)據(jù)的類(lèi)
class iconImg(object):
def __init__(self,size,idiom,filename,scale):
self.size = size
self.idiom = idiom
self.filename = filename
self.scale = scale
def show(self):
print("%s,%s,%s,%s"%(self.size,self.idiom,self.filename,self.scale))
def get_wh(self):
return (float(self.size.split('x')[0]))*(float(self.scale.split('x')[0]))
if __name__ == '__main__':
ImgManager.sharedinstance().handle_icon_images()
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
python 利用turtle庫(kù)繪制笑臉和哭臉的例子
今天小編就為大家分享一篇python 利用turtle庫(kù)繪制笑臉和哭臉的例子,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-11-11
Python析構(gòu)函數(shù)__del__定義原理解析
這篇文章主要介紹了Python析構(gòu)函數(shù)__del__定義原理解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-11-11
Python統(tǒng)計(jì)純文本文件中英文單詞出現(xiàn)個(gè)數(shù)的方法總結(jié)【測(cè)試可用】
這篇文章主要介紹了Python統(tǒng)計(jì)純文本文件中英文單詞出現(xiàn)個(gè)數(shù)的方法,結(jié)合實(shí)例形式總結(jié)分析了Python針對(duì)文本文件的讀取,以及統(tǒng)計(jì)文本文件中英文單詞個(gè)數(shù)的4種常用操作技巧,需要的朋友可以參考下2018-07-07
pandas DataFrame 根據(jù)多列的值做判斷,生成新的列值實(shí)例
今天小編就為大家分享一篇pandas DataFrame 根據(jù)多列的值做判斷,生成新的列值實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-05-05
Python學(xué)習(xí)之線程池與GIL全局鎖詳解
本文我們將學(xué)習(xí)線程池的創(chuàng)建與全局鎖。線程池的創(chuàng)建于進(jìn)程池的原理是相同的;關(guān)于GIL全局鎖,暫時(shí)沒(méi)有代碼上的練習(xí),而是對(duì)其概念進(jìn)行一個(gè)簡(jiǎn)單的啟蒙,感興趣的可以了解一下2022-04-04
django admin 根據(jù)choice字段選擇的不同來(lái)顯示不同的頁(yè)面方式
這篇文章主要介紹了django admin 根據(jù)choice字段選擇的不同來(lái)顯示不同的頁(yè)面方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-05-05
Python滲透測(cè)試入門(mén)之Scapy庫(kù)的使用詳解
Scapy?是一個(gè)用來(lái)解析底層網(wǎng)絡(luò)數(shù)據(jù)包的Python模塊和交互式程序,該程序?qū)Φ讓影幚磉M(jìn)行了抽象打包,使得對(duì)網(wǎng)絡(luò)數(shù)據(jù)包的處理非常簡(jiǎn)便。本文就來(lái)聊聊它的具體使用,希望對(duì)大家有所幫助2023-03-03
Python 實(shí)現(xiàn)輸入任意多個(gè)數(shù),并計(jì)算其平均值的例子
今天小編就為大家分享一篇Python 實(shí)現(xiàn)輸入任意多個(gè)數(shù),并計(jì)算其平均值的例子,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-07-07

