spritepacker

command module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 13, 2025 License: MIT Imports: 5 Imported by: 0

README


🧩 SpritePacker | 精灵图打包工具

SpritePacker is a 2D sprite sheet packing tool, designed for game developers


📦 Installation | 安装

go get -u github.com/91xusir/spritepacker

or

git clone https://github.com/91xusir/spritepacker.git
cd spritepacker
go build .

🛠 Usage | 使用方式

CLI 命令行

Options 参数说明
Flag Description (EN) 描述(中文)
-input Input image folder 输入图片文件夹
-output Output atlas & metadata directory 输出图集和元数据目录
-maxw Maximum atlas width 最大图集宽度
-maxh Maximum atlas height 最大图集高度
-trim Trim transparent edges 裁剪透明边缘
-rotate Allow 90-degree rotation 允许旋转优化
-autosize Auto resize the canvas 自动调整尺寸
-format Output format (json, xml, etc.) 输出格式(json、xml 等)

📂 Output Example | 输出示例

├── atlas.png        # Packed texture 图集
├── atlas.json       # Metadata 元数据(包含坐标、尺寸等)

🧠 Algorithm | 算法

  • Basic
  • MaxRects
  • Skyline

🧪 Go API Example | Go 语言调用示例


Documentation

Overview

Package main provides a command-line tool for sprite atlas packing and unpacking.

This tool supports: - Creating optimized sprite atlases from individual images - Unpacking existing sprite atlases back to individual images - Multiple packing algorithms and heuristics - Various sprite processing options

Usage:

spritepacker -input <dir> [options]       # Pack mode
spritepacker -unpack <json> [options]     # Unpack mode

Packing Options:

-input string      Input directory containing sprite images (required for packing)
-output string     Output directory (default "output")
-maxw int          Maximum atlas width (default 2048)
-maxh int          Maximum atlas height (default 2048)
-padding int       Padding between sprites (default 2)
-rotate            Allow sprite rotation to save space
-pot               Force power-of-two atlas dimensions
-pma               Use premultiplied alpha
-name string       Base name for output files (default "atlas")
-sort              Sorts sprites before packing (default true)
-trim              Trims transparent edges (default true)
-tolerance int     Transparency tolerance for trimming (0-255, default 1)
-same              Enable identical image detection (default true)
-algo int          Packing algorithm (0=Basic, 1=Skyline, 2=MaxRects)
-heuristic int     MaxRects heuristic (0-4, see docs)

Unpacking Options:

-unpack string     JSON file to unpack (required for unpacking)
-img string        Atlas image path (optional, will search by name)
-output string     Output directory for unpacked sprites

Examples:

# Pack sprites with default settings
spritepacker -input ./sprites -output ./atlases

# Pack with custom settings
spritepacker -input ./sprites -maxw 1024 -maxh 1024 -padding 4 -rotate

# Unpack atlas
spritepacker -unpack ./atlases/atlas.json -output ./unpacked

The package includes: - Multiple packing algorithms (Basic, Skyline, MaxRects) - Support for common image formats (PNG, JPEG, BMP, TIFF) - Sprite trimming and optimization features - JSON metadata generation

Directories

Path Synopsis
Package pack provides texture packing utilities, including support for rotation, transparent pixel trimming, automatic resizing and so on.
Package pack provides texture packing utilities, including support for rotation, transparent pixel trimming, automatic resizing and so on.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL