How to get row/column info in tile filenames?

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
amcleod
Posts: 2
Joined: 2015-04-06T22:34:41-07:00
Authentication code: 6789

How to get row/column info in tile filenames?

Post 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.

Thanks...
---
Angus

Version: ImageMagick 6.8.6-10 2013-09-19 Q16 http://www.imagemagick.org
OS: Linux 3.10.30-smp (Slackware 14.1)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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 ^
  tiled_%%[filename:tile].gif
(From an example at http://www.imagemagick.org/Usage/crop/#crop_tile )
snibgo's IM pages: im.snibgo.com
amcleod
Posts: 2
Joined: 2015-04-06T22:34:41-07:00
Authentication code: 6789

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

Post 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

#!/bin/bash
/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!
---
Angus
Post Reply