A simple PNG image material cutting tool implemented with Go, it performs the non-transparent continuous area cut on the Alpha (transparency channel) using the DFS (Depth-First Search) algorithm, and obtains the position information of the sprite sheet in the material package.
-
It achieves the extraction of the sprite sheet position area of the material package (to JSON format file), which can accurately locate the required materials. For why sprite sheets are needed, you can refer to this or this.
-
It achieves the cutting of the sprite sheet, that is, extracting all elements from a large material picture.
-
If you have other desired output formats, feel free to modify this code~
-
If your materials are not PNG images with transparency channels, you can use tools such as GIMP, Photoshop to perform preliminary editing (add transparent layers, magic wand/color selection to remove background).
go build main.go
- Run
./main -input example/icons.png -output output -mode sprite
- Output
You will get a split JSON file in the
output
directory, which contains the sprite sheet information: The coordinates are based on the upper left corner as the zero point,h
is height,w
is width,x1
,y1
are the upper left coordinates,x2
,y2
are the lower right coordinates.
The formatted material location JSON information can be conveniently used in your game and app development process.
You will get the split small pictures in the output
directory
使用Go实现的一个简单的PNG图片素材切割工具,基于在Alpha(透明度通道)使用DFS(深度优先搜索)算法做非透明连续区域的切割,得到素材包的雪碧图位置信息。
-
如果您有其他希望的输出格式,可以自由的修改此代码~
-
如果您的素材不是带透明通道的PNG图片,可以使用GIMP,Photoshop等工具先进行见到那的编辑(增加透明图层、魔棒/色彩选择去除底部背景)。
go build main.go
- 运行
./main -input example/icons.png -output output -mode sprite
- 输出
您将在目录
output
下得到分割得到JSON文件,里面包含了雪碧图信息: 坐标以左上方为零点,h是高度,w是宽度,x1,y1是左上坐标,x2,y2是右下坐标。
格式化的素材位置JSON信息可以在您的游戏、应用开发过程中方便的使用。