I have a number of input images that contain multiple smaller images, all of them in a single row. All the contained images are the same size. So, for example, the image input.png
may be 480x48
and contain 10 48x48
images, all in one row.
Using the imagemagick convert
tool (or any other tool supplied with the defaul imagemagick suite), I want to write a bash script that takes an input image, the number of images to cut, and then cuts them all into individual images.
The user interaction i can do, but I've not been able to get convert
to do the actual cutting. Can anyone suggest something? From reading the manual pages, i think this should work:
convert 'input.png[0x0+48+48]' output.png
but I get an error:
convert: no pixels defined in cache
tb_icons_l.png' @ magick/cache.c/OpenCache/3572. convert: No IDATs written into file
1.png' @ coders/png.c/PNGErrorHandler/1391.
Any ideas?
I would do it like that:
convert input.png -crop 48x48 +repage +adjoin output_%02d.gif
Read more at Tile Cropping, in ImageMagick documentation.
I believe you've got the position and size swapped. Try:
convert 'input.png[48x48+0+0]' output.png
The third image would be:
convert 'input.png[48x48+96+0]' output.png
Or
convert 'input.png[48x48+0+96]' output.png
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With