https://github.com/unitoftime/packer
Super basic sprite packing library
https://github.com/unitoftime/packer
go golang
Last synced: 10 months ago
JSON representation
Super basic sprite packing library
- Host: GitHub
- URL: https://github.com/unitoftime/packer
- Owner: unitoftime
- License: mit
- Created: 2020-10-04T21:06:45.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-08-18T22:14:43.000Z (almost 3 years ago)
- Last Synced: 2025-08-19T17:41:04.539Z (11 months ago)
- Topics: go, golang
- Language: Go
- Homepage:
- Size: 2.24 MB
- Stars: 16
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Packer
This is a work in progress texture packing standalone. Right now the packing algorithm isn't very optimized in terms of speed, but probably finds a fairly well packed set of images.
### Install
```
go install github.com/unitoftime/packer/cmd/packer@latest
```
Note: the binary is held in `cmd/packer/` so the suffix `/...` is required to install the `packer` binary to your go path.
### Usage
Basic
```
packer --input sprites --output ./path/to/file
```
#### Flags
```
--input - The directory of the input folder
--output - The filename of the output json and png files
--extrude - The amount to extrude each sprite
--stats - If true, display statistics
--size - The width and height of the packed atlas
```
#### Serialized Json
The JSON file created by the `packer` binary is of form `SerializedSpritesheet`. (See `packer.go` for reference):
```
type SerializedRect struct {
X,Y,W,H float64
}
type SerializedPos struct {
X,Y float64
}
type SerializedDim struct {
W,H float64
}
type SerializedFrame struct {
Frame SerializedRect
Rotated bool
Trimmed bool
SpriteSourceSize SerializedRect
SourceSize SerializedDim
Pivot SerializedPos
}
type SerializedSpritesheet struct {
ImageName string
Frames map[string]SerializedFrame
Meta map[string]interface{}
}
```
### Example Output
You can go to the `packer/cmd/images/` and use the `generate.sh` script to generate some random images. Then you can rerun the test.

### Remaining Work
* Create package to let developers dynamically pack images (ie not through command line)
* Dynamically resize atlas image (rather than using a size flag)
* Optimize