I would like to have a script to process a set of image files in png format, lets's say inside of one directory. We can also assume the images have the same size. The processing should contain of the following actions: select certain region, make it transparent, repeat for the next file.

Just an example to illustrate what I mean:

enter image description here

should be turned into

enter image description here


enter image description here


enter image description here

edit: @Paolo Gibbelini and @Scribblemacher, you made good suggestions. However I need now to slightly change my requirements. The width of the input image may be different and with of the crop area should be equal to the image width. The height of the crop area should be constantly 69 pixels. Can I achieve that with ImageMagick as well? Would it be correct to pass geometry like 9999x9999+0+69 for the crop?

1 Answer 1


This kind of operation could be simply performed with Imagemacick using crop function.

In your example:

convert your_image.png -crop 423x275+0+113 -background transparent -flatten cropped_image.png

The output is:

Cropped image

Using a batch file you can process all your images.


convert works even using in the geometry dimensions greater than the dimensions of the image itself:

convert your_image.png  -crop 9999x9999+0+69 -background transparent -flatten cropped_image.png

other cropped image

Fore more complex operations you can get the attributes of the image using the identify command in your batch file.

As evidenced by @Scribblemacher, you can use mogrify in order to simplify the batch operation. Be aware that mogrify overwrites original files.

  • 2
    I agree--Imagemagick is the tool for this job. You can also also use mogrify instead of convert. Mogrify works similar to convert, but can accept a wildcard (e.g. *.png in a directory) and overwrite the original files. Commented Jul 22, 2015 at 15:35
  • Please see the updated question.
    – Danny Lo
    Commented Jul 23, 2015 at 13:06
  • I've updated my answer. Commented Jul 23, 2015 at 13:21
  • That would mean I need to parse output of identify, modify it corresponding to my needs and pass it to mogrify/convert, right?
    – Danny Lo
    Commented Jul 23, 2015 at 17:00
  • No, you can simply use 9999x9999+0+69 as geometry for crop, my example should work. Use the parsing only for more complex operations. Commented Jul 24, 2015 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.