Page 1 of 1

0-padding numbers in filename when using fx calculation

Posted: 2016-12-21T04:10:00-07:00
by occular
I'm splitting a large image into tiles, with the X, Y coord of each tile in the tile filenames:

Code: Select all

convert "livingroom0-2560x1280.jpg" -crop 512x512 -set filename:tile "%[fx:page.x/512]_%[fx:page.y/512]" \
    +repage "tile_%[filename:tile].png"
This works fine but I'd like to 0-pad the filenames so that instead of "tile_3_1.png" I get "tile-03_01.png".
Can anyone give me a hint how to do this?

My best effort so far is:

Code: Select all

convert "livingroom0-2560x1280.jpg" -crop 512x512 -set filename:yLoc "%[fx:page.y/512]" \
     -set filename:xLoc "%[fx:page.x/512]" +repage "tile_%[filename:xLoc]_%[filename:yLoc].png"
But this doesn't work, I get filenames like"tile_3_%[f1.png".

Re: 0-padding numbers in filename when using fx calculation

Posted: 2016-12-21T04:15:56-07:00
by occular
Sorry, can't edit my post for some reason, the second code example should read:

convert "livingroom0-2560x1280.jpg" -crop 512x512 -set filename:yLoc "%[fx:page.y/512]" \
-set filename:xLoc "%[fx:page.x/512]" +repage "tile_%02[filename:xLoc]_%02[filename:yLoc].png"

and when I run that, I get errors.

Re: 0-padding numbers in filename when using fx calculation

Posted: 2016-12-21T20:34:12-07:00
by anthony
At the moment there is no way to 'format' the number output from a FX calcualtion. It was thought about an planned though.
see the Plan.... in Future Developments section of IM Examples
http://www.imagemagick.org/Usage/bugs/
IMv7 Percent Escapes and FX Expression Development
Section "Formatting Percent Escapes..."
http://www.imagemagick.org/Usage/bugs/I ... rcent.html