TexturePacker批处理python
TexturePacker版本 4.2.1
前言:因为水平有限,错误再所难免,望指正, 大家如果有购买能力的话,希望购买TexturePacker正版,不要再用盗版了。好东西就应该支持。
1.安装TexturePacker Command Line Tool
1.1 Mac下安装 TexturePacker => Install Command Line Tool => Install
1.2 win下安装 必须配置环境变量。
2.TexturePacker命令说明(主要命令)
2.1 --texture-format
--texture-format <id> Sets the format for the textures.The format type is automatically derived from the sheet's file nameif possible.Available formats:png PNG (32bit)png8 PNG (8bit indexed)pvr3 PowerVR Texture Format, PVR Version 3pvr3gz PowerVR Texture Format, PVR Version 3, compressed with gzippvr3ccz PowerVR Texture Format, PVR Version 3, compressed with zlib, cocos2d headerjpg JPG image format, lossy compression, no transparencybmp 24 bit BMPtga Targa Image Formattiff Tagged Image File Formatpkm PKM image format, ETC1 compressionwebp WebP lossless / lossy formatatf Adobe Texture Formatpvr2 PowerVR Texture Format, PVR Version 2, deprecatedpvr2gz PowerVR Texture Format, PVR Version 2, compressed with gzip, deprecatedpvr2ccz PowerVR Texture Format, PVR Version 2, compressed with zlib, cocos2d header, deprecate
纹理输出格式,常用的 png,png8,pvr3ccz,pkm,jpg。
png全平台都适用,
png8文件小但效果比起png来说有一些损失,并且对一些图片渐变处理效果损失更加明显,如果效果看不过去还是用png吧
pvr3ccz pvr3ccz是pvr2ccz升级版,添加了一些功能,可以使用其他像素格式比如 ETC1,pvr2ccz 以前是不支持的。
pkm 主要用于ETC1
jpg 由于没有alpha通道,所以常用于背景图,压缩到80%的效果和原图差距不大,但压缩比例很吓人,文件小效果好,目前背景没有alpha通道的就用的这个。由于在cocos2d 2.x版本上加载速度慢,并且消耗内存大,根据实际情况选用。
2.2 --opt 像素格式
--opt <pixelformat> Optimized output for given pixel formats. Supported formats are:RGBA8888 32bit, 8bit/channel, 8bit transparencyBGRA8888 32bit, 8bit/channel, 8bit transparencyRGBA4444 16bit, 4bit/channel, 4bit transparencyRGB888 24bit, 8bit/channel, no transparencyRGB565 16bit, 5bit red, 6bit green, 5bit blue, no transparancyRGBA5551 16bit, 5bit/channel, 1bit transparancyRGBA5555 20bit, 5bit/channel, 5bit transparancyPVRTCI_2BPP_RGB PVRTC compression, 2bit per pixelPVRTCI_4BPP_RGB PVRTC compression, 4bit per pixelPVRTCI_2BPP_RGBA PVRTC compression, 2bit per pixelPVRTCI_4BPP_RGBA PVRTC compression, 4bit per pixelPVRTCII_2BPP PVRTC2 compression, 2bit per pixelPVRTCII_4BPP PVRTC2 compression, 4bit per pixelALPHA 8bit transparencyALPHA_INTENSITY 8bit intensity, 8bit transparencyETC1_RGB ETC1 compressionETC1_A ETC1 Alpha channel onlyETC1_RGB_A ETC1 RGB + ETC1 AlphaETC2_RGB ETC2 compressionETC2_RGBA ETC2 AlphaDXT1 Compressed with DXT1, 1 bit transparencyDXT5 Compressed with DXT5, transparencyATF_RGB ETC1+DXT1+PVRTC4, no transparencyATF_RGBA ETC1/ETC1+DXT5+PVRTC4, no transparency
像素格式常用 RGBA8888,RGBA4444,RGB888,RGB565,RGBA5551,RGBA5555,PVRTCI_4BPP_RGBA,ETC1_RGB,ERC1_A。
RGBA8888 效果最好消耗内存比较大。 内存消耗32bpp
RGBA4444 效果比起RGBA8888在某些图片上丢失得有点大。 但消耗内存是 RGBA8888的一半。 内存消耗16bpp
RGB888 少个alpha通道,内存占用是 RGBA8888 的 四分之三。内存消耗24bpp
RGB565 效果上比 RGB888差一些,但对于有些图片还是可以接受的, 但没有alpha通道。内存消耗16bpp
RGBA5551 对于透明渐变少的可以采用效果 比 RGBA4444好。内存消耗16bpp
RGBA5555 alpha通道增加 自然透明效果好了,但内存消耗也增加了。 仙存消耗24bpp
PVRTCI_4BPP_RGBA 效果上比RGBA8888要差一些,但内存消耗极小,加载速度也快,渲染速度快,在ios上完全是可以接受的,强烈建议ios 用这个格式。内存消耗4bpp
ETC1_RGB 消耗内存极小,加载速度比RGBA8888快,渲染速度快,效果也比较不错,但没有alpha通道,这也是ETC1被一直吐槽的点,所以后来有个ETC2。内存消耗4bpp
ETC1_A 和ETC1_RGB 组合在一起用,给ETC1_RGB提供alpha通道,达到透明效果,建议android可以选用这种方法来处理ETC1没有alpha通道的缺点。内存消耗4bpp
ETC1_RGB、ETC1_A可以通过shader对纹理进行两次采集处理达到RGBA的效果,这里就不讨论这个问题了。
内存消耗计算方式 :假如一张图是 1024 * 888
ETC1内存消耗 = 1024 * 888 * 4bpp / 8 = 454656byte = 444KB
PVRTCI_4BPP_RGBA内存消耗 = 1024 * 888 * 4bpp / 8 = 454656byte = 444KB
RGB888内存消耗 = 1024 * 888 * 24bpp / 8 = 2727936byte = 2664KB
RGBA8888内存消耗 = 1024 * 888 * 32bpp / 8 = 3637248byte = 3552KB
RGBA4444内存消耗 = 1024 * 888 * 16bpp / 8 = 1818624byte = 1776KB
2.3 --data 输出纹理文件的信息数据路径 plist
--data <filename> Name of the data file to write
2.4 --sheet 输出图集路径
--sheet <filename> Name of the sheet to write, see texture-format for formats available
2.5 --dither-type 颜色抖动
--dither-type <dithertype> Dithering to improve quality of color reduced imagesNearestNeighbour no ditheringLinear no ditheringFloydSteinberg Floyd Steinberg, no alphaFloydSteinbergAlpha Floyd Steinberg, with alphaAtkinson Atkinson, no alphaAtkinsonAlpha Atkinson, alphaPngQuantLow PNG-8 only: minimum ditheringPngQuantMedium PNG-8 only: medium ditheringPngQuantHigh PNG-8 only: strong dithering
对图片颜色进行一些插值处理。不同参数算法不同。
PngQuantLow,PngQuantMedium,PngQuantHigh选用PNG8 可以试试这三个参数。用了比原PNG8好
2.6 --format
--format <format> Format to write, default is cocos2dAvailable formats:2dtoolkit 2D Toolkit exporterandengine Format for AndEngineagk Format for AppGameKitbatterytech BatteryTech Exporterbhive Format for BHivecaat Exporter for CAAT - the Canvas Advanced Animation Toolkitcegui Format for CEGUI / OGREcocos2d plist format version 3 for cocos2dcocos2d-v2 old plist format version 2 for cocos2d (deprecated)cocos2d-x plist format version 3 for cocos2d-x with polygon packingcorona-imagesheet Exporter for Corona(TM) SDK using new image sheet format.css css format for web designeaseljs Exporter for EaselJS.gideros Format for Giderosjson-array Text file for json/html as arrayjson Text file for json/html as hashkwik Exporter for Kwik using new image sheet format.less Creates a LESS file that can be incorporated into a sprites arrangementlibgdx text file for lib GDXlibRocket Exporter to demonstrate how to crate your own exportersmelonjs Data file for MelonJSmoai Format for Moaimolecule Exporter for Molecule Frameworkmonogame Input format for the MonoGame TexturePacker Importerorx Orx Exporterpanda Exporter for Panda Enginephaser-json-array JSON array data for Phaserphaser-json-hash JSON hash data for Phaserpixijs Data file for PixiJSsass-mixins Exporter for SASS.shiva3d-jpsprite Shiva3D with JPSprite extensionshiva3d Exporter for Shiva3D.slick2d Format for Slick2Dsparrow xml file for Sparrow/Starling SDKspine text file for Spinespritesheet-only Exports only the sprite sheet without data filespritekit plist format for SpriteKit, Objective-C header filespritekit-swift plist format for SpriteKit, with swift class filespriter JSON file for Spriterspritestudio OPTPiX SpriteStudio 5 CellMap File.tresensa Exporter for TreSensa TGE.uikit Exporter for UIKitunity Text file for Unity(R), json format with .txt endingunity-texture2d Input format for the Unity(R) TexturePacker Importerunreal-paper2d Format for UnrealEngine / Paper2dvplay JSON file for V-Play enginewave-engine-1 WaveEngine Sprite Sheetx2d Export to x2d engine format.xml Generic XML formatplain Exporter to demonstrate how to crate your own exporters
纹理打包方式
cocos2d-x 新版本的多边形打包方式,目前cocos studio 不支持
cocos2d-v2 老版本的打包方式,现在已经被废弃,但我还是用的这个。
cocos2d 新版本的打包方式 目前cocos studio 不支持
其他方式比如unity,unreal,spritekit如果有用的可以自行研究
2.7 --multipack 多图集打包
--multipack Create multiple sprite sheets if not all sprites match into a single one
避免一个图集包含不完所以精灵,开起则会生成多张图集。但要在 --data --sheet 加入 {n} 索引会从0开始
2.8 --maxrects-heuristics
MaxRects--maxrects-heuristics Heuristic for MaxRects algorithmBest BestShortSideFit ShortSideFitLongSideFit LongSideFitAreaFit AreaFitBottomLeft BottomLeftContactPoint ContactPoint
maxrect的算法方式
2.9 --enable-rotation 精灵旋转
--enable-rotation Enables rotation of sprites (overriding file format's defaults)
开起旋转,得到更小的图集
2.10 --trim-mode 透明像素处理
--trim-mode <value> Remove transparent parts of a sprite to shrink atlas size and speed up renderingNone Keep transparent pixelsTrim Remove transparent pixels, use original size.Crop Remove transparent pixels, use trimmed size, flush position.CropKeepPos Remove transparent pixels, use trimmed size, keep position.Polygon Approximate sprite contour with polygon path.
常用Trim。
Trim 删除图片透明像素,用原图片像素大小,在帧动画中常用,
None 保证原样大小,和透明像素。 不建议用。图集大。
Crop 删除图片透明像素,用删除后的图片像素大小,位置改变
CropKeepPos 删除图片透明像素,用删除后的图片像素大小,位置不变
Polygon 多边形方式,得到图集更小,目前cocos2d 也不支持多边形精灵。
建议使用Trim,其他用处不大。
2.11 --basic-sort-by 和 --basic-order
Basic--basic-sort-by Sort order for the sprite listBest BestName NameWidth WidthHeight HeightArea AreaCircumference Circumference--basic-order Sorting directionAscending AscendingDescending Descending
选用 Name 和 Ascending就行了。这个我觉得不用多做了解,按名称升序方式排序在 list中
2.12 --max-size 最大纹理图集大小
--max-size <int> Sets the maximum width and height for the texture in auto size mode, default is 2048
建议使用2048,最大不超过4096,各个机型支持图集大小有区别。 以前
2.13 --size-constraints 图集高宽约束方式
--size-constraints <value> Restrict sizesPOT Power of 2 (2,4,8,16,32,...)WordAligned Texture width is multiple of 2 (for 16-bit formats)AnySize Any size
POT 2次幂方式
AnySize 任意大小
2.14 --force-publish
--force-publish Ignore smart update hash and force re-publishing of the files
强制重新再次生成,忽略智能更新,废弃以前的 --smart-update
2.15 --shape-padding 和 --border-padding
--shape-padding <int> Sets a padding around each shape, value is in pixels, default is 2--border-padding <int> Sets a padding around each the border, value is in pixels, default is 2
--shape-padding 边框填充像素
--border-padding 相当于精灵之间的间距像素
2.16 --scale 和 --scale-mode精灵缩放
--scale <float> Scales all images before creating the sheet. E.g. use 0.5 for half size--scale-mode <mode> Use mode for scaling:Smooth SmoothFast Fast (Nearest Neighbor)Scale2x Scale2x (fixed 2x upscaling)Scale3x Scale3x (fixed 3x upscaling)Scale4x Scale4x (fixed 4x upscaling)Eagle Eagle2x (fixed 2x upscaling)Hq2x Hq2x (fixed 2x upscaling)
主要用于不同 分辨率的机型和处理纹理大小,如果只用一套资源来适配。不用关心。scale 设为1就行
2.17 --replace 正则表达式
--replace <regexp>=<string> Replaces matching parts of the sprite's name with <string>Uses full regular expressions, make sure to escape the expression
正则表达式来修改精灵名,--replace ^={sheetName}_ win和mac得到的结果不一样。
3. python 批处理
目录结构
#!/usr/bin/python
#encoding=utf-8
import io
import os
import sys
import hashlib
import string
import rerootPath = os.path.abspath(os.path.join(sys.argv[0], os.pardir))# # input paths
ImageDir= os.path.join(rootPath, "input")# temporary path to place the sprite sheets
OutputDir = os.path.join(rootPath, "output")#PVRTC4
OutputDirPVRTC4 = os.path.join(OutputDir, "PVRTC4") #ios 中PVRTC4输出目录
#ETC
OutputDirETC = os.path.join(OutputDir, "ETC") #android 中 ETC输出目录
#PNG
OutputDirPNG = os.path.join(OutputDir, "PNG") #通用 中 PNG输出目录OutputDirPNG8 = os.path.join(OutputDir, "PNG8") #通用 中 PNG输出目录# # path of the texture packer command line tool
TP="TexturePacker"print("ImageDir = " + ImageDir)
print("OutputDir = " + OutputDir)
print("OutputDirPVRTC4 = " + OutputDirPVRTC4)
print("OutputDirETC = " + OutputDirETC)
print("OutputDirPNG = " + OutputDirPNG)
print("OutputDirPNG8 = " + OutputDirPNG8)
print("TP = " + TP)#文件输出目录
def createPath(cPath):if not os.path.isdir(cPath):os.mkdir(cPath)# --trim-sprite-names 去除png等后缀
# --multipack 多图片打包开起,避免资源图太多,生成图集包含不完全,开起则会生成多张图集。
# --maxrects-heuristics macrect的算法 参数 Best ShortSideFit LongSideFit AreaFit BottomLeft ContactPoint
# --enable-rotation 开起旋转,计算rect时如果旋转将会使用更优的算法来处理,得到更小的图集
# --border-padding 精灵之间的间距
# --shape-padding 精灵形状填充
# --trim-mode Trim 删除透明像素,大下使用原始大小。 参数 None Trim Crop CropKeepPos Polygon
# --basic-sort-by Name 按名称排序
# --basic-order Ascending 升序
# --texture-format 纹理格式
# --data 输出纹理文件的信息数据路径 plist
# --sheet 输出图集路径 png
# --scale 1 缩放比例 主要用于低分辨率的机子多资源适配。
# --max-size 最大图片像素 一般我是用的2048,超过2048以前的有些android机型不支持。
# --size-constraints 结纹理进行大小格式化,AnySize 任何大小 POT 使用2次幂 WordAligned
# --replace 正则表达式,用于修改plist加载后的名称
# --pvr-quality PVRTC 纹理质量
# --force-squared 强制使用方形
# --etc1-quality ETC 纹理质量
def pack_textures(inputPath, outputPath, opt, scale, maxSize, sheetSuffix, textureFormat, sizeConstraints, sheetName, otherParams, fileNameSuffix):packCommand = TP + \" --multipack" \" --format cocos2d-v2" \" --maxrects-heuristics best" \" --enable-rotation" \" --shape-padding 2" \" --border-padding 0" \" --trim-mode Trim" \" --basic-sort-by Name" \" --basic-order Ascending" \" --texture-format {textureFormat}" \" --data {outputSheetNamePath}{fileNameSuffix}.plist" \" --sheet {outputSheetNamePath}{fileNameSuffix}.{sheetSuffix}" \" --scale {scale}" \" --max-size {maxSize}" \" --opt {opt}" \" --size-constraints {sizeConstraints}" \" {inputPath}" \" {otherParams}"# win 和 mac 上处理正则表达式结果不一样if sys.platform == "win32":packCommand = packCommand + " --replace (.png)$=" \" --replace \\b={sheetName}_" \" --replace {sheetName}_$=.png"else:packCommand = packCommand + " --replace ^={sheetName}_"packCommand = packCommand.format(textureFormat=textureFormat,outputSheetNamePath=os.path.join(outputPath,sheetName) + "_{n}",sheetName=sheetName,sheetSuffix=sheetSuffix,scale=scale,maxSize=maxSize,opt=opt,sizeConstraints=sizeConstraints,inputPath=inputPath,otherParams=otherParams,fileNameSuffix=fileNameSuffix)os.system(packCommand)if __name__ == '__main__':createPath(OutputDir)createPath(OutputDirPVRTC4)createPath(OutputDirETC)createPath(OutputDirPNG)createPath(OutputDirPNG8)for sheet in os.listdir(ImageDir):iPath = os.path.join(ImageDir, sheet)if os.path.isdir(iPath): pack_textures(iPath,OutputDirPVRTC4,'PVRTCI_4BPP_RGBA',1,2048,'pvr.ccz',"pvr3ccz","POT",sheet,"--pvr-quality best --force-squared", "")pack_textures(iPath,OutputDirETC,'ETC1_RGB',1,2048,'pkm',"pkm","AnySize",sheet,"--etc1-quality high-perceptual", "")pack_textures(iPath,OutputDirETC,'ETC1_A',1,2048,'pkm',"pkm","AnySize",sheet,"--etc1-quality high-perceptual", "_alpha")pack_textures(iPath,OutputDirPNG,'RGBA8888',1,2048,'png',"png","AnySize",sheet,"--png-opt-level 7", "")pack_textures(iPath,OutputDirPNG8,'RGBA8888',1,2048,'png',"png8","AnySize",sheet,"--png-opt-level 7 --dither-type PngQuantHigh", "")
TexturePacker批处理python相关推荐
- 基于sen2sor的并行批处理python代码,五倍速提高大气校正速率
博主进行了实验,发现在固态硬盘中该方法才会有效提速,在普通机械硬盘中速度和串行处理没有区别 只需修改代码中的sen2cor_path为你的sen2sor解压目录中的L2A_Process.bat所在位 ...
- python调用ffmpeg合并_用ffmpeg命令处理mp4剪切与合并
1. 剪切: ./ffmpeg -ss 00:00:06 -t 00:00:12 -i input.mp4 -vcodec copy -acodec copy output.mp4 意思是从截取从6秒 ...
- Kindle:自动追更之云上之旅
2017年5月27: 原来的程序是批处理+Python脚本+Calibre2的方式,通过设定定时任务的方式,每天自动发动到自己的邮箱中.缺点是要一直开着电脑,又不敢放到服务器上~~ 鉴于最近公司查不关 ...
- 单链队列实现及基本操作
#include<iostream> using namespace std; typedef struct LinkQueueNode//队列节点结构 { int data; Lin ...
- 考研学校的爬虫(自己写的可能会有点菜
最近因为准备考研所以就把要考研的学校的招生简章给爬了下来 开机启动 我爬 我怕我忘了最新的学校通告所以才写的 首先确定目标~~ 然后到研究生院查看资料 这里我就不讲了然后 这里进入正题 爬取页面 先是 ...
- c 爬虫 html解析,C# 爬虫 Jumony html解析
前言 前几天写了个爬虫,然后认识到了自己的不足. 烽火情怀推荐了Jumony.Core,通过倚天照海- -推荐的文章,也发现了Jumony.Core. 研究了2天,我发现这个东西简单粗暴,非常好用,因 ...
- python批处理修改文件的名字
[十一月的萧邦] 蛋蛋说我写的博客叫做情感博客,所以现在不忍心,出来水一篇,毕竟为了庆祝十一月的到来. 十一月有周杰伦的新专辑,当时我们买了藏在书包里,开运动会,一本漫画,一副耳机,躺在绿油油的草地上 ...
- 【Android 逆向】使用 Python 编写 APK 批处理分析工具
文章目录 一.涉及到的工具和脚本 二.使用 Python 编写 APK重打包工具 三.博客源码 一.涉及到的工具和脚本 apktool.jar : 反编译 APK 文件使用到的工具 ; 参考 [And ...
- Python 技术篇-设置windows开机自动启用Jupyter服务,BAT批处理脚本启用jupyter服务设置,设置jupyter默认启动位置的方法
把下面的代码存储为 bat 结尾的批处理脚本. @echo off jupyter notebook 放到存放 python 项目的位置,在这里启动服务,默认进的就是这个目录. 然后给 bat 脚本创 ...
最新文章
- (0025)iOS 开发之Xcode常用快捷键
- 2021-01-10 Halcon初学者知识 【10】形状匹配 【二】模板的形状匹配
- 【Scratch】青少年蓝桥杯_每日一题_2.23_小猫来回走
- 若依前后端分离版怎样修改主页面和浏览器上的图标和标题
- Hadoop之InputFormat数据输入详解
- 计算机专业用锐龙笔记本,轻松应对工作挑战——ThinkPad T14 锐龙版,适合办公的笔记本电脑...
- 物联网架构----双机热备Keepalived了解
- 单位阶跃信号是周期信号吗_vivoS7e是5G手机吗-支持5G吗-5G信号怎么样
- ubuntu 远程连接服务器以及文件传输
- flex布局演示(可线上运行项目)
- 面向 Android* Jelly Bean 的英特尔® 凌动™ x86 映像安装说明 — 推荐
- 年薪 40w 的应届生
- 汽车电子研究报告:下一个苹果产业链
- Android Gson to Json类型转换异常解决方法
- 调度站入口有n节软席和硬席车厢,将所有软席调到硬席之前
- 骑士旅行问题(骑士走棋盘)
- 【CTO讲堂】企业该如何打造自身的“安全免疫系统”?
- JSX列表渲染(五)——4种写法:基本写法 遍历写法 map遍历写法(常用-加工处理数组的每一项数据,最后形成一个新的数组) 列表遍历可以直接写到表达式中
- iOS网络NSURLSession使用详解
- Wipro将与SAP共同开发零售时尚行业解决方案