Page 1 of 1

Re: How to trim the transparent pixels from the image border?

Posted: 2008-04-22T20:27:49-07:00
by fmw42
This seems to work for me:

Create image with transparent border:
convert -size 100x100 xc:white white.png
convert white.png -bordercolor none -border 50x50 test.png

identify test.png
test.png PNG 200x200 200x200+0+0 DirectClass 16-bit 784b

Trim border:
convert test.png -trim +repage test2.png

identify test2.png
test2.png PNG 100x100 100x100+0+0 DirectClass 16-bit 494b

Re: How to trim the transparent pixels from the image border?

Posted: 2009-06-01T19:44:48-07:00
by gotskill10
The current implementation of "trim" removes pixels from the edges of an image until it hits a different pixel. Nothing in the example makes it discriminate solely against transparent pixels. It merely just removes color/transparent pixels from the edges until it hits one of a different color code.

How would you call the command to trim *only* transparent pixels so that it wouldn't otherwise trim off color pixels under any circumstances.

This example would trim the image even if you filled it with a non-transparent border.

Re: How to trim the transparent pixels from the image border?

Posted: 2009-06-01T19:58:09-07:00
by fmw42
gotskill10 is right, -trim does not look for any particular color and works the way he said it does. the first user made that assumption, not I. I just provided a demo that it works for transparent borders.

Re: How to trim the transparent pixels from the image border?

Posted: 2009-06-01T20:16:23-07:00
by anthony
To trim with a particular color, add a border of that color. The fuzz setting will then center on that color.