to trim a series of png

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
dejavukaz

to trim a series of png

Post by dejavukaz »

I want to make a sprite sheet of a character kicking and I know that I can use Montage to do that.

Before I start to arrange the image array,
I need to trim a series of pngs exported from 3ds max with alpha so the transparency part wouldn't take too much space.
It's like that I put all the pngs in different layers in the same file in photoshop and trim the picuture.
everything png would be with the same width and height and the extra space is gone.

Is it possible to do with imagemagick?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: to trim a series of png

Post by fmw42 »

for each image, do

convert image.png -trim result.png

That will trim the transparency to the minimum size of the opaque figure inside.

If they all end up different sizes and you want to then pad back to some common size, then given you know what size you want (the largest of the lot), then

convert image.png -background none -gravity center -extent WxH result.png

then the image will be padded back with transparency to size WxH


If you have a lot of images, you can put them all in a folder, say test1, and use mogrify. But it is recommended that you have mogrify put the results into another folder say test2

cd test1
mogrify -path fullpathto/test2 -format .png -trim *.png


see

http://www.imagemagick.org/Usage/basics/#mogrify
http://www.imagemagick.org/Usage/crop/#extent
http://www.imagemagick.org/Usage/crop/#trim
Post Reply