tags:

views:

23

answers:

2

What is the correct way to an dice an image into N x N sub-tile images?

Thanks,
Doug

A: 

Check here: http://www.imagemagick.org/Usage/crop/

John at CashCommons
A: 

Thanks,

Actually I futzed a bit and came up with the correct imagemagick incantations.

Here's the tcsh version.

Dice an image into a 4 x 4 grid (resultant images numbered sequentual). The number system is interpreted as: col + row * nrows:

convert -crop 25%x25% image.png tile-prefix.png

Often it is desirable to remap the sequential numbering to row x column. For example if you are using CATiledLayer in an iOS app and will need to ingest the correct tiles for a given scale. Here's how:

while ( $i < $number_of_tiles )  
while -> set r = `expr $i \/ 4`  
while -> set c = `expr $i \% 4`  
while -> cp tile-prefix-$i.png tile-prefix-${r}x${c}.png  
while -> echo $i  
while -> @ i++  
while -> end
dugla
You could just use FX Escapes to make IM name the tiles accordingly, something like `-set filename:tile "%[fx:page.x/4+1]_%[fx:page.y/4+1]"`
erjiang
Nice. Very cool, thanks erjiang.
dugla