python icon生成小工具

在项目制作的过程中,有可能会出现一张图片需要有不同的大小去适应不同的设备和位置时,手动去一个个制作比较麻烦,本人通过网上学习粗略敲了一段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位浮点型像素。")

下载传送门

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值