Page 1 of 1

cropped files named by column and row

Posted: 2019-04-08T04:06:24-07:00
by Madani
Greetings – newbie using ImageMagick-7.0.8-39-Q16-x64, Windows 10.

I need a large png (16384pixels-wide) split into 256 pixel-wide pngs. That much is working just fine with;

Code: Select all

Magick convert -crop 256x256 large.png 6-%d.gif
However I need the filenames to be the column and row position in a 64x64 tile grid (4096 total), and my question is how to do this;
0-0.gif
0-1.gif
0-2.gif
… etc.
63-63.gif

Is there an easy command or do I need to use loops? If so, at the risk of embarrassing myself horribly, here's my pseudocode for how I imagine it might approximately go;

Code: Select all

tileArray[4096]; 
tileNumber=0;
for(column=0;column<63;column++){
	for(row=0;row<63;row++){
		tileArray[tileNumber] = [column] + "-" + [row];
		tileNumber++;
	}
}
Magick convert -crop 256x256 large.png tileArray[%d].gif
Am I far off? I'm sure my syntax, among other things, must be hopeless – help would be greatly appreciated!

Cheers

Re: cropped files named by column and row

Posted: 2019-04-08T05:08:10-07:00
by snibgo

Re: cropped files named by column and row

Posted: 2019-04-08T05:24:27-07:00
by Madani
Cheers, got it.

Magick convert big.png -crop 256x256 -set filename:f "%[fx:page.x/256]%/-%[fx:page.y/256]" +repage +adjoin "6-%[filename:f].gif"