Skip to main content

pysprites

Sometimes, designer will give you a visual production, and that you need to crop the little sprites off from the files, merge them into a png files, and write a css files for such sprites.

This tools make everything in onkey.

Install

$ pip install pysprites

Example

$ pysprites -i page1.psd -m icon- -b -r -c page1.css -o page1.png

This command will import layers whose name starts with icon-, from page1.psd, reposition them, output the css for each sprite to page1.css, and output the merged png to page1.png

Command line

$ pysprites [args...]

-i a.psd b.psd ... : import psd layer from psd files (need psd_tools)
-a x.png y.png ... : add png files
-m filter  : only handle layer or image name startswith filter
-p padding : add padding for each sprite
-r         : reposition sprites
-cp string : use string as css class prefix
-b         : gen sprite width and height for css
-c out.css : output css to file
-o out.png : output merged png to file

Framework

Actually, everything is in a single file : pysprites/sprites.py.

In a task, everything present as a “General Sprite Process Group” (gsp), it is struct is as follow:

gsp :: (width, height, img, padding, prefix, args)
img :: list of [[name, [width, height],[left, top], PIL_object]

And the gsp go though handlers, a handler reposition the img, and a handler save it to png, and so on.

Reposition Algorithm

  1. Select two most height sprites and the final image height.

  2. Find a lowest gap.

  3. Select a longest sprite that can be insert to left, and insert it.

  4. If cannot insert it, fill the gap and goto step2.

  5. Repeat untail every sprite has been inserted.

Using a EdgeLines struct to maintain the lowest gap, and the gsp_reposition function implements this algorithm. See the code in pysprites/sprites.py

Contribute

I think this tools is good enough for me. However, Welcome for new handlers, for example, import the layer from a GIMP xcf file, or new reposition algorithm, or any participation !

Enjoy it!

Metadata

Release files for pysprites 2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pysprites 2.0
File Size Uploaded Provenance Actions
pysprites-2.0.tar.gz 5.1 kB Without provenance Details for pysprites-2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pysprites 2.0
File Interpreter ABI Platform Actions
pysprites-2.0-py2.7.egg Legacy Egg format - - Details for pysprites-2.0-py2.7.egg

Total release size: 16.3 kB

Release files / pysprites-2.0.tar.gz

Download URL pysprites-2.0.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
54c24f8f47f74dc4784a1cf79e562badeacd7a9051245e048d7e791fba9471e6
BLAKE2b-256 checksum
How to use checksums
e2c6c94a6dad6a2820510322c7f1faef292096bbe1d1f5d1b491b2341795d927
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pysprites-2.0-py2.7.egg

Download URL pysprites-2.0-py2.7.egg
Size 11.1 kB
Tags Egg
SHA-256 checksum
How to use checksums
e932ee0b5928cad2e71138350d389b7c834ab58f811f77f4736e4d5b76245e88
BLAKE2b-256 checksum
How to use checksums
c7bb876cb7833ae4912738bffceb29742ae68f72b4e19bead423c07996ac8358
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for pysprites 2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page