an package to create sprite sheets or sprite atlases
Project description
PyTexturePacker
![Documentation Status](https://pypi-camo.freetls.fastly.net/d24ee3cdb4e041ed645244f257bc7a169a73fc15/68747470733a2f2f72656164746865646f63732e6f72672f70726f6a656374732f7079746578747572657061636b65722f62616467652f3f76657273696f6e3d6d6173746572)
PyTexturePacker is an open source python package, released under the MIT License.
A subset of feature of TexturePacker has been implemented in this package.
Features
MaxRectsBinPack algorithm is used to generate sprite sheet in this package.
MaxRectsBinPack
MaxRectsBinPack is currently the best packing algorithm. It tries to use the least texture space by applying different heuristics when placing the sprites.
MaxRects
Best-known algorithm for packing textures
Is fast and has a high packing ratio
Enable rotation for best results
Installation
Clone The Package
$ git clone git@github.com:wo1fsea/PyTexturePacker.git
Install Dependency
$ pip install Pillow
or:
$ easy_install Pillow
Usage
Here comes an example of using PyTexturePacker to pack texture images from a directory.
from PyTexturePacker import Packer
def pack_test():
# create a MaxRectsBinPacker
packer = Packer.create(max_width=2048, max_height=2048, bg_color=0xffffff00)
# pack texture images under directory "test_case/" and name the output images as "test_case".
# "%d" in output file name "test_case%d" is a placeholder, which is a multipack index, starting with 0.
packer.pack("test_case/", "test_case%d")
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.
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.
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”.
Contribute
Issue Tracker: github.com/wo1fsea/PyTexturePacker/issues
Source Code: github.com/wo1fsea/PyTexturePacker
Any types of contribution are welcome. Thanks.
Support
If you are having issues, please let us know. Please feel free to contact me. email: quanyongh@foxmail.com
License
The project is released under the terms of MIT License. You may find the content of the license here, or LICENSE.txt inside the project directory.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.