Using ImageMagick to Divide an Image
Quite some time ago I wanted to make a heavily modified version of the “Once Upon a Time” story telling game. I wanted to incorporate a lot of the elements my Sister and I would include in our stories when we were writing them as teenagers. They were truly terrible stories. Anyway, to do this I scanned the original card set as sheets of nine cards, and then altered them with new illustration, new characters, locations, objects, events and stupid comments. Now, several years later, after having written stories using the physical set of altered cards, I’m keen to write some more stories. Seeing as I’ve given away the physical set, I want a digital set from which I can draw a selection of cards. To do this I’d need to go through each sheet of cards and crop out the individual cards. This felt like an incredibly tedious task, so I wondered about setting Imagemagick onto it. After a very short amount of time in the Imagemagick user manual I found that this could be done. Command in hand, I had processed the image sheets into 132 seperate cards in a matter of less than a second. So, here is the command I used;
To process a single file
convert Modified_OUaT003.jpg -crop 3x3@ +repage +adjoin cards_%d.jpg
Where Modified_OUaT003.jpg
is the filename to be processed, 3x3@
is the number of division, and the cards_%d.jpg
is the output filename format.
while I haven’t tried it in Imagemagick version 7, I expect the command would be;
magick convert Modified_OUaT003.jpg -crop 3x3@ +repage +adjoin cards_%d.jpg
To process a directory of images and drop the individual card files into an output directory;
mogrify -path '/home/hamy/Documents/Imagemagick_Demo/Processed' -crop 3x3@ +repage -quality 95 -format jpg *.jpg
Where -path '/home/hamy/Documents/Imagemagick_Demo/Processed'
defines the output directory, -format jpg
is the output file format, and ```.jpg is the filenames for Imagemagick to process.
For Imagemagick version 7, I expect the command to be;
magick mogrify -path '/home/hamy/Documents/Imagemagick_Demo/Processed' -crop 3x3@ +repage -quality 95 -format jpg *.jpg