Page 1 of 1

How to get row/column info in tile filenames?

Posted: 2015-04-06T23:14:39-07:00
by amcleod
I'm working with largish images (up to 12000x12000 pixels) and want to break them up into tiles. I've been using:

Code: Select all

convert -crop 256x256 bigimage.jpg tiled_%06d.jpg
which does the job fine. But while the tile names contain sequence numbers, it would be very convenient if the names indicated the row and column position of each tile in it's name, like tiled_003_018.jpg for example. I can't figure a way to do this in ImageMagick, and I can't think of a way to do it with a shell script or simple perl script. Because all the large images are of varying size, I don't know how many rows and columns will result from any particular run of convert -crop.

Can anyone suggest a way to achieve my goal? I've googled for hours, and read IM's documentation pertaining to escapes until my eyeballs hurt, but I've not found anything that does the job.


Version: ImageMagick 6.8.6-10 2013-09-19 Q16
OS: Linux 3.10.30-smp (Slackware 14.1)

Re: How to get row/column info in tile filenames?

Posted: 2015-04-07T00:26:57-07:00
by snibgo
Windows BAT syntax:

Code: Select all

convert ^
  bigimage.jpg ^
  -crop 256x256 ^
  -set filename:tile "%%[fx:page.x/256+1]_%%[fx:page.y/256+1]" ^
  +repage +adjoin ^
(From an example at )

Re: How to get row/column info in tile filenames?

Posted: 2015-04-07T09:03:43-07:00
by amcleod
Thank you so much for your help. The documentation on escapes begins to make more sense with your example before me. I eventually ended up with

Code: Select all

/usr/bin/convert bigimage.jpg -crop 256x256 \
  -set filename:tile "%[fx:page.x/256+1001]_%[fx:page.y/256+1001]" \
    +repage +adjoin "tiled_%[filename:tile].jpg"
which did the trick nicely. (I added 1001 rather than 1 so as to get constant width numbers in the output.)

Thanks again!