Question

I have a collection of transparent .png files. They are all a standard canvas size of 220x132 but the image might only be for example 150x40 with the rest of the image being transparent background..

Is there a way to crop the canvas size to the actual visible image area using linux script?

Was it helpful?

Solution

ImageMagick is a powerful framework for doing all kinds of image editing from the command line. Cropping is a part of it.

See the documentation here: http://www.imagemagick.org/Usage/crop/ Of special interest for you might be the trim command: http://www.imagemagick.org/Usage/crop/#trim

However, it might very well be, that a simple repage does the job. This depends on how your PNG image is built: PNGs can contain layer boundary information. trim will be perfectly fine for you, but repage might be faster when dealing with a huge amount of images.

When ImageMagick is installed, try these commands: identify, display, convert, mogrify on your images.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top