Page 1 of 1
can I auto-crop transperant edges off?
Posted: 2008-09-24T12:00:41-07:00
by brainlord
Using RGB+alpha PNG files.
most are 100 pixels square or so (some are taller)
problem: 1% of them are 500, 600 even 1024 pixels square with only the first 100 square pixels or so used (the top left corner). The rest is solid alpha.
I can manually crop to 100 square pixels, but that cuts stuff off.
Can IM automatically crop an image to a rectangle that throws away unused alpha space?
(this is similar to the "Crop to Mask" or "Crop to Selection" actions of photo editing programs)
aha
Re: can I auto-crop transperant edges off?
Posted: 2008-09-24T13:25:22-07:00
by fmw42
brainlord wrote:Using RGB+alpha PNG files.
Can IM automatically crop an image to a rectangle that throws away unused alpha space?
(this is similar to the "Crop to Mask" or "Crop to Selection" actions of photo editing programs)
aha
Yes,
pad rose: image with transparency as test image:
convert rose: -bordercolor none -border 50 rose_a.png
trim transparency
convert rose_a.png -trim +repage rose_a_trim.png
If your image is not transparent all around, then pad by a few pixels all around as above, then use -trim.
See:
http://www.imagemagick.org/script/comma ... s.php#trim
Re: can I auto-crop transperant edges off?
Posted: 2008-09-25T17:56:52-07:00
by anthony
Adding a border around an image will ensure that when -trim is performed only the color of the added border will be trimmed.
Be sure you include a +repage to remove the trim virtual canvas information it leaves behind.
Question do you want all the images to be 100x100 when finished?
Also your original question implies that only the 100x100 at the top left is of interest. If so You can force the image to be 100x100 pixels, adding or removing the pixels to force them to be 100x100 but using -extent
http://www.imagemagick.org/Usage/crop/#extent
Code: Select all
convert image.png -background none -extent 100x100 image_new.png
Note you can save the image back to its destination if you are sure this does what you want. Or you can process a whole list of such images using "mogrify".
Code: Select all
mogrify -background none -extent 100x100 image_*.png