Page 1 of 1

Sprite sheet dimentions

Posted: 2017-07-06T11:50:51-07:00
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.

Re: Sprite sheet dimentions

Posted: 2017-07-06T13:23:06-07:00
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.

Re: Sprite sheet dimentions

Posted: 2017-07-07T03:49:30-07:00
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"

Re: Sprite sheet dimentions

Posted: 2017-07-07T09:33:12-07:00
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.