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

[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.本站资源都是白菜价出售,同样的东西,我们不卖几百,也不卖几十,甚至才卖几块钱,一个永久会员能下载全站100%源码了,所以单独购买也好,会员也好均不提供相关技术服务。
2.如果源码下载地址失效请联系站长QQ进行补发。
3.本站所有资源仅用于学习及研究使用,请必须在24小时内删除所下载资源,切勿用于商业用途,否则由此引发的法律纠纷及连带责任本站和发布者概不承担。资源除标明原创外均来自网络整理,版权归原作者或本站特约原创作者所有,如侵犯到您权益请联系本站删除!
4.本站站内提供的所有可下载资源(软件等等)本站保证未做任何负面改动(不包含修复bug和完善功能等正面优化或二次开发);但本网站不能保证资源的准确性、安全性和完整性,由于源码具有复制性,一经售出,概不退换。用户下载后自行斟酌,我们以交流学习为目的,并不是所有的源码都100%无错或无bug;同时本站用户必须明白,【安安资源网】对提供下载的软件等不拥有任何权利(本站原创和特约原创作者除外),其版权归该资源的合法拥有者所有。
5.请您认真阅读上述内容,购买即以为着您同意上述内容,由于源码具有复制性,一经售出,概不退换。
安安资源网 » [python]python打包小图片到大图(类型于TexturePacker的功能)