cropped files named by column and row

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
Madani
Posts: 2
Joined: 2019-04-07T23:31:34-07:00
Authentication code: 1152

cropped files named by column and row

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: cropped files named by column and row

Post by snibgo »

snibgo's IM pages: im.snibgo.com
Madani
Posts: 2
Joined: 2019-04-07T23:31:34-07:00
Authentication code: 1152

Re: cropped files named by column and row

Post 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"
Post Reply