Sprite sheet dimentions

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
MikeVansoz
Posts: 2
Joined: 2017-07-06T11:46:08-07:00
Authentication code: 1151

Sprite sheet dimentions

Post by MikeVansoz »

Is there a way to get sprite sheet dimensions when montaging images sequence? I need width and height data to be appended automatically to file name.
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Sprite sheet dimentions

Post by GeeMack »

MikeVansoz wrote: 2017-07-06T11:50:51-07:00Is there a way to get sprite sheet dimensions when montaging images sequence? I need width and height data to be appended automatically to file name.
Without knowing which version of IM you're using or what platform or OS you're working on, generally I'd say that's an extremely simple task. The exact best answer may be quite different from one situation to another, so check the suggestions at THIS link, then give us more specific information about your requirements.
MikeVansoz
Posts: 2
Joined: 2017-07-06T11:46:08-07:00
Authentication code: 1151

Re: Sprite sheet dimentions

Post by MikeVansoz »

Win 7 x64
ImageMagick 6.9.3-7 Q16 x64 2016-03-06

Ok, so I break video file into png sequence using ffmpeg:

Code: Select all

ffmpeg -i "%%i" -r 10 -f image2 "%%~dpni\%%10d.png"
Then merge it all in one square sprite sheet with montage:

Code: Select all

montage "%%~dpni\*.png" -background transparent -geometry +0+0 -tile 8x "%%~dpni_sprite.png"
And I need to add some info about sprite sheet in output filename, like so:
"%%~dpni_SPRITE_WIDTHxSPRITE_HEIGHT.png"
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Sprite sheet dimentions

Post by GeeMack »

MikeVansoz wrote: 2017-07-07T03:49:30-07:00And I need to add some info about sprite sheet in output filename, like so:
"%%~dpni_SPRITE_WIDTHxSPRITE_HEIGHT.png"
After you get the original broken into its separate frames with "ffmpeg", you can use IM's "convert" to calculate the dimensions of the final montage. A command like this will output the width and height of the montage in the form of "1920x1080"...

Code: Select all

convert *.png -set option:thesize "%%[fx:w*8]x%%[fx:ceil(n/8)*h]" -append -format %%[thesize] info:
To put that output into a variable in a Windows BAT script you can use "for" like this...

Code: Select all

for /f %%I in (
   'convert *.png -set option:thesize "%%[fx:w*8]x%%[fx:ceil(n/8)*h]" -append -format %%[thesize] info:'
   ) do (
   set WIDTH_HEIGHT=%%I
)
Then in your montage command you can use that variable %WIDTH_HEIGHT% as part of the output file name.

Edited to add: If your montage uses any amount of spacing other than "-geometry +0+0" you'd have to figure that additional width and height into your "convert" command, too. It would be just barely more complicated, but in concept pretty much the same thing.
Post Reply