依星源码资源网,依星资源网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1136|回复: 0

[python]python打包小图片到大图(类型于TexturePacker的功能)

[复制链接] |主动推送主动推送

3814

主题

3853

帖子

4706

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
4706
发表于 2021-5-6 13:15:15 | 显示全部楼层 |阅读模式
[python]python打包小图片到大图(类型于TexturePacker的功能)PyTexturePacker
可以将文件夹中的图片打包成一张大图及plist文件。

  1. #!/usr/bin/python
  2. # -*- coding: UTF-8 -*-

  3. from PyTexturePacker import Packer

  4. def pack_test():
  5.     # create a MaxRectsBinPacker
  6.     packer = Packer.create(max_width=2048, max_height=2048, bg_color=0xffffff00)
  7.     # pack texture images under directory "test_case/" and name the output images as "test_case".
  8.     # "%d" in output file name "test_case%d" is a placeholder, which is a multipack index, starting with 0.
  9.     packer.pack("test_case/", "test_case%d")

  10. pack_test()
复制代码

参数说明:

Packer Setting
bg_color
The background color of output image. The pixels of the empty area in the output image will be filled with bg_color. The default value is 0x00000000, which is in format of "RGBA". A tuple of values can also be accepted, like (R, G, B, A).

texture_format
Choose the texture format that the output file will use, for example ".jpg". The default texture format is ".png".

max_width
Sets the maximum width for the texture, default is 4096.

max_height
Sets the maximum height for the texture, default is 4096.

enable_rotated
Allows the rotating of sprites clockwise or counterclockwise by 90 degrees if they have a better fit in the texture. Might not be supported by all game/web frameworks.

force_square
Forces the texture to have a squared size.

border_padding
Border padding is the space between the sprites and the border of the sprite sheet. Value adds transparent pixels around the borders of the sprite sheet. Default is 2.

shape_padding
Shape padding is the space between sprites. Value adds transparent pixels between sprites to avoid artifacts from neighbor sprites. The transparent pixels are not added to the sprites. Default is 2. Use a value of at least 2 to avoid dragging in pixels from neighbor sprites when using OpenGL rendering.

inner_padding
Adds transparent pixels to the inside of the sprite, growing it. Default is 0.

There are two uses for this:

It can help in preventing cut-off artifacts near the edges of scaled sprites. E.g. if your sprite has a few pixels along its own boundaries, scaling the sprite up or down won't let these pixels appear as gaps or cuts.
It considerably reduces aliasing along the polygon edges when rotating trimmed or cropped sprites. E.g. if your sprite has many pixels along its own boundaries, it will be drawn more smoothly when rotating it.
trim_mode
Removes transparent pixels from a sprite's border. This shrinks the sprite's size, allows tighter packing of the sheet, and speeds up rendering since transparent pixels don't need to be processed. Pixels with an alpha value below this value will be considered transparent when trimming the sprite. Allowed values: 0 to 255, default is 0. When it's set to 0, the trim mode is disabled. Very useful for sprites with nearly invisible alpha pixels at the borders.

reduce_border_artifacts
Adds color to transparent pixels by repeating a sprite's outer color values. These color values can reduce artifacts around sprites and removes dark halos at transparent borders. This feature is also known as "Alpha bleeding".

extrude
Extrude repeats the sprite's pixels at the border. Sprite's size is not changed.

There are two uses for this:

Reduce flickering in some cases where sprites have to be put next to each other in the final program.
Check if sprite outlines are OK. E.g. if you want to use sprites to create tilemaps this allows you to see if there are semi-transparent pixels at the borders of the tiles.
atlas_format
Choose the texture config format that file will use. Available options "plist" or "json". The default texture config output format is "plist".

扫码关注微信公众号,及时获取最新资源信息!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

免责声明:
1、本站提供的所有资源仅供参考学习使用,版权归原著所有,禁止下载本站资源参与商业和非法行为,请在24小时之内自行删除!
2、本站所有内容均由互联网收集整理、网友上传,并且以计算机技术研究交流为目的,仅供大家参考、学习,请勿任何商业目的与商业用途。
3、若您需要商业运营或用于其他商业活动,请您购买正版授权并合法使用。
4、论坛的所有内容都不保证其准确性,完整性,有效性。阅读本站内容因误导等因素而造成的损失本站不承担连带责任。
5、用户使用本网站必须遵守适用的法律法规,对于用户违法使用本站非法运营而引起的一切责任,由用户自行承担
6、本站所有资源来自互联网转载,版权归原著所有,用户访问和使用本站的条件是必须接受本站“免责声明”,如果不遵守,请勿访问或使用本网站
7、本站使用者因为违反本声明的规定而触犯中华人民共和国法律的,一切后果自己负责,本站不承担任何责任。
8、凡以任何方式登陆本网站或直接、间接使用本网站资料者,视为自愿接受本网站声明的约束。
9、本站以《2013 中华人民共和国计算机软件保护条例》第二章 “软件著作权” 第十七条为原则:为了学习和研究软件内含的设计思想和原理,通过安装、显示、传输或者存储软件等方式使用软件的,可以不经软件著作权人许可,不向其支付报酬。若有学员需要商用本站资源,请务必联系版权方购买正版授权!
10、本网站如无意中侵犯了某个企业或个人的知识产权,请来信【站长信箱312337667@qq.com】告之,本站将立即删除。
郑重声明:
本站所有资源仅供用户本地电脑学习源代码的内含设计思想和原理,禁止任何其他用途!
本站所有资源、教程来自互联网转载,仅供学习交流,不得商业运营资源,不确保资源完整性,图片和资源仅供参考,不提供任何技术服务。
本站资源仅供本地编辑研究学习参考,禁止未经资源商正版授权参与任何商业行为,违法行为!如需商业请购买各资源商正版授权
本站仅收集资源,提供用户自学研究使用,本站不存在私自接受协助用户架设游戏或资源,非法运营资源行为。
 
在线客服
点击这里给我发消息 点击这里给我发消息 点击这里给我发消息
售前咨询热线
312337667

微信扫一扫,私享最新原创实用干货

QQ|免责声明|依星源码资源网 ( 鲁ICP备2021043233号-3 )|网站地图

GMT+8, 2024-3-29 22:50

Powered by Net188.com X3.4

邮箱:312337667@qq.com 客服QQ:312337667(工作时间:9:00~21:00)

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