找回密码
 立即注册
查看: 1307|回复: 2

[脚本] 批量导出appstore图片-python根据一张图导出不同尺寸的icon及launchImage

[复制链接]
发表于 2019-8-5 17:01 | 显示全部楼层 |阅读模式

要切换到python 3以上版本,这里用的别名 alias python3 可用sudo vi ~/.bashrc 编辑添加
alias python3='/Library/Frameworks/Python.framework/Versions/3.7'

python3 从python网站上下载,用法:python3 脚本路径 要进行裁剪的图片 导出类型(icon或launchImage) 是否竖屏
举例:
  1. python3 /Users/yusiyuan/Downloads/exportImg.py /Users/yusiyuan/Downloads/未命名文件夹8/A7CCADE7E97F85687A64C50AEF46DF6F.jpg icon 1
  2. 图片路径imgPath:/Users/yusiyuan/Downloads/未命名文件夹8/A7CCADE7E97F85687A64C50AEF46DF6F.jpg
复制代码
  1. from PIL import  Image
  2. import os
  3. import sys
  4. imgPath=sys.argv[1]
  5. exportType=sys.argv[2]
  6. isVertical=sys.argv[3]
  7. print ("图片路径imgPath:%s"%imgPath)
  8. print ("导出类型:%s"%exportType)
  9. print ("是否竖屏:%s"%isVertical)
  10. #创建icon方法
  11. imageDirectory =imgPath
  12. imageSize = [29,50,57,58,60,72,76,80,87,100,114,120,144,152,180,1024]

  13. def createImage(size):
  14.     im = Image.open(imageDirectory)
  15.     im.resize((size,size), Image.ANTIALIAS).save(imageDirectory+"icon%dx%d.png"%(size,size))

  16. def start():
  17.     for size in imageSize:
  18.        createImage(size)
  19. #创建launchImage方法
  20. imageLSizeW=[1242,1125,750,640,640,2048,1668,1668,1536,768];
  21. imageLSizeH=[2688,2436,1334,1136,960,2732,2388,2224,2048,1024];

  22. def createImageL(sizeW,sizeH):
  23.     im = Image.open(imageDirectory)
  24.     im.resize((sizeW,sizeH), Image.ANTIALIAS).save(imageDirectory+"icon%dx%d.png"%(sizeW,sizeH))
  25. def startLaunch():
  26.         for index in range(len(imageLSizeW)):
  27.                 if isVertical=="1":
  28.                             createImageL(imageLSizeW[index],imageLSizeH[index])
  29.                 elif isVertical=="0":
  30.                         createImageL(imageLSizeH[index],imageLSizeW[index])
  31.                 else:
  32.                             createImageL(imageLSizeW[index],imageLSizeH[index])

  33. if __name__ == "__main__":
  34.         if exportType == "icon":
  35.                     start()
  36.         elif exportType == "launchImage":
  37.                 startLaunch()
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
 楼主| 发表于 2019-10-8 14:31 | 显示全部楼层
  1. from PIL import  Image
  2. import os
  3. import sys
  4. imgPath=sys.argv[1]
  5. exportType=sys.argv[2]
  6. isVertical=sys.argv[3]
  7. print ("图片路径imgPath:%s"%imgPath)
  8. print ("导出类型:%s"%exportType)
  9. print ("是否竖屏:%s"%isVertical)
  10. #创建icon方法
  11. imageDirectory =imgPath
  12. imageSize = [29,50,57,58,60,72,76,80,87,100,114,120,144,152,167,180,1024]

  13. def createImage(size):
  14.         im = Image.open(imageDirectory)
  15.         index = imageDirectory.rfind('/')
  16.         newPath=imageDirectory[0:index]
  17.         newPath=newPath+"/"+"icon_%dx%d.png"%(size,size)
  18.         print("导出成功,路径为:%s"%newPath)
  19.         im.resize((size,size), Image.ANTIALIAS).save(newPath)

  20. def start():
  21.         for size in imageSize:
  22.                 createImage(size)
  23. #创建launchImage方法
  24. imageLSizeW=[1242,1242,1125,750,640,640,2048,1668,1668,1536,768];
  25. imageLSizeH=[2688,2208,2436,1334,1136,960,2732,2388,2224,2048,1024];

  26. def createImageL(sizeW,sizeH,oneImagePath,indexL):
  27.         im = Image.open(oneImagePath)
  28.         index = oneImagePath.rfind('/')
  29.         newPath=oneImagePath[0:index]
  30.         newPath=newPath+"/"+str(indexL)+"_launchImage_%dx%d"%(sizeW,sizeH)+".png"
  31.         print("导出成功,路径为:%s"%newPath)
  32.         im.resize((sizeW,sizeH), Image.ANTIALIAS).save(newPath)
  33. def startLaunch(oneImagePath,indexL):
  34.         for index in range(len(imageLSizeW)):
  35.                 if isVertical=="1":
  36.                         createImageL(imageLSizeW[index],imageLSizeH[index],oneImagePath,indexL)
  37.                 elif isVertical=="0":
  38.                         createImageL(imageLSizeH[index],imageLSizeW[index],oneImagePath,indexL)
  39.                 else:
  40.                         createImageL(imageLSizeW[index],imageLSizeH[index],oneImagePath,indexL)

  41. if __name__ == "__main__":
  42.         if exportType == "icon":
  43.                         start()
  44.         elif exportType == "launchImage":
  45.                 arrImagePath=imgPath.split("+")
  46.                 for indexL in range(len(arrImagePath)):
  47.                         tmp=arrImagePath[indexL]
  48.                         startLaunch(tmp,indexL)
复制代码

点评

更新了一版带加号 批量导出的 使用示例:  详情 回复 发表于 2019-10-8 14:32
 楼主| 发表于 2019-10-8 14:32 | 显示全部楼层
资源大湿 发表于 2019-10-8 14:31

更新了一版带加号 批量导出的
使用示例:
  1. python3 /Users/yusiyuan/Desktop/SlotsProject/python/exportImg.py /Users/yusiyuan/ConnectNumber/image/7E4C52A3A08E3EE9B131ED7F28D349F4.JPG+/Users/yusiyuan/ConnectNumber/image/4788FD2A3C21992BCDABE68332F3F2ED.JPG+/Users/yusiyuan/ConnectNumber/image/C6A91B713477E2D9966A2DDFD7389632.JPG+/Users/yusiyuan/ConnectNumber/image/F5DA50F28F29712106924103C482C1AE.JPG launchImage 1
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-4-28 12:56 , Processed in 0.102712 second(s), 32 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表