How to write a bash script that cuts images into pieces using image magic?

I have several input images that contain several smaller images, and they are all on the same line. All images contained are the same size. So, for example, the image input.pngmay also 480x48contain 10 48x48images, all in one line.

Using the imagemagick tool convert(or any other tool that comes with the defaul imagemagick package), I want to write a bash script that takes an input image, the number of images to cut, and then cuts them all into separate images.

User interaction, which I can do, but I could not get convertfor 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: tb_icons_l.png' @ magick/cache.c/OpenCache/3572. convert: No IDATs written into file 1.png '@ encoders /png.c/PNGErrorHandler/1391 pixels are not defined in the cache .

Any ideas?

+5
source share
2 answers

I believe that you have a position and the size has changed. Try:

convert 'input.png[48x48+0+0]' output.png

Third image:

convert 'input.png[48x48+96+0]' output.png

or

convert 'input.png[48x48+0+96]' output.png
+5
source

I would do it like this:

convert input.png -crop 48x48  +repage  +adjoin  output_%02d.gif

Read more in Trimming Tiles in the ImageMagick documentation .

+9
source

All Articles