texpack packs lot of arbitrary images to texture atlases.
This program is useful for some modern graphics libraries like OpenGL if you have many small textures.
Usage: texpack -s <dir_name> -o <tex_name> [keys] texpack -l <file> -o <tex_name> [keys] Possible keys are: Required: -s --source-dir=DIR NAME directory with source images -l --list=FILE NAME file with list of source images (each line - full file name to image) -o --output=FILE TEMPLATE output atlases name Optional: -r --relative placement info in float format (x/result_width, y/result_height) -f --file=FILE NAME write placement info to text file except stdout -w --width=WIDTH width of atlases -W --max-width=WIDTH maximal width of atlases (default 2048) -H --max-height=HEIGHT maximal height of atlases (default 2048) -F --format=FORMAT user defined format of output -b --border=NUMBER border size around each source images -n --native-size do not use discrete sizes for atlases (2, 4, 8,.. 256, 512, 1024...) -a --separate-by-alpha pack images width alpha-channel separatelly -R --use-rotations rotate images counter-clockwise when packing -v --version version info -u --help this help FORMAT can contain any characters and special printf-like macros: %1$s - atlas name (rn) %2$s - source image name (sn) %3$u - source image left absolute coordinate in atlas (la) %4$u - source image top absolute coordinate in atlas (ta) %5$u - source image right absolute coordinate in atlas (ra) %6$u - source image bottom absolute coordinate in atlas (ba) %7$f - source image left relative coordinate in atlas (lr) %8$f - source image top relative coordinate in atlas (tr) %9$f - source image right relative coordinate in atlas (rr) %10$f - source image bottom relative coordinate in atlas (br) By default using next FORMAT (delimeters are TABs): %s %s %u %u %u %u With option --relative using next format: %s %s %7$f %8$f %9$f %10$f Examples: texpack -s /home/user/pictures -o textures -H 1024 -w 1024 texpack -l /home/user/filelist.txt -o textures Both examples produce few big images (textures0.png, textures1.png...) in current directory. First example limits size of images to 1024x1024. Second example limits images to 2048x2048. Size of last produced image may be less than limits.
This program takes list of source images, load they all, determine size of result texture, but not above MAX_WIDTH x MAX_HEIGHT. It packs all source images to this texture. If it is impossible (max possible size of result texture is less than needed to pack all source images) then creates new result texture, pack remainded images to it...
To the placements file it outputs filename of each result texture and source image width sizes and position placed to it.
If no option --native-size specified all sizes of texture atlases are rounded to power of 2 (1, 2, 4, 8, 16... 1024, 2048...)
Tipical quality of packing is ~80-98% (it depends of relation of source images to atlas sizes).
Example:
I take few icons from KDE 3.5 with all standart sizes (22x22, 32x32, 48x48, 64x64 and 128x128) and place them to directory 'a':
$ texpack --source-dir ./a -o result result0.png artsmidimanager128 0 0 128 128 result0.png artsfftscope128 128 0 256 128 result0.png artsenvironment128 256 0 384 128 result0.png artsaudiomanager128 384 0 512 128 result0.png artsmediatypes128 0 128 128 244 result0.png svn_add 128 128 192 192 result0.png svn_switch 192 128 256 192 result0.png svn_status 256 128 320 192 result0.png svn_remove 320 128 384 192 result0.png svn_merge 384 128 448 192 result0.png svn_branch 448 128 512 192 result0.png presence_away 128 192 177 240 result0.png next 177 192 225 240 result0.png previous 225 192 273 240 result0.png player_playlist 273 192 321 240 result0.png presence_online 321 192 369 239 result0.png presence_offline 369 192 417 239 result0.png mail_new 417 192 449 224 result0.png mail_get 449 192 481 224 result0.png colorize 481 192 505 216 result0.png configure 481 216 503 238 result0.png color_line 417 224 433 242 result0.png bookmark_folder 433 224 449 240 result0.png color_fill 449 224 465 240 result0.png clear_left 465 224 481 240 result0.png compfile 481 238 503 260 result0.png mail_generic 321 239 353 271 result0.png mail_forward 353 239 385 271 result0.png mail_find 385 239 417 271 result0.png colorpicker 128 240 150 262 result0.png contexthelp 150 240 172 262 result0.png contents2 172 240 194 262 result0.png contents 194 240 216 262 result0.png connect_no 216 240 238 262 result0.png connect_established 238 240 260 262 result0.png connect_creating 260 240 282 262 result0.png charset 433 240 449 256 result0.png cancel 282 240 298 256 result0.png bottom 449 240 465 256 result0.png bookmarks_list_add 298 240 314 255 result0.png bookmark_add 465 240 481 255 result0.png bookmark 417 242 433 257 result0.png bookmark_toolbar 0 244 16 259 result0.png mail_delete 16 244 48 276 result0.png mail_send 48 244 80 276 result0.png mail_replylist 80 244 112 276 result0.png mail_replyall 433 256 465 288 result0.png mail_reply 282 256 314 288 result0.png mail_post_to 465 260 497 292
Where columns are:
1st - name of texture atlas
2nd - name of source image without extention
3rd - left image position in result texture (x coordinate)
4th - top image position in result texture (y coordinate)
5th - right image position in result texture (x + width)
6th - bottom image position in result texture (y + height)
and result texture were saved in current directory with name result0.png:
Sources can be accessed here.