Page 1 of 1
auto-trimming on one side only works on top and bottom.
Posted: 2012-02-19T13:59:48-07:00
by ange4771
i tried to use this:
http://www.imagemagick.org/Usage/crop/#trim_oneside
so I use command lines such as:
>convert opcodes_tables06.png -gravity East -background white -splice 0x1 -background black -splice 0x1 -trim +repage -chop 0x1 opcodes_tables06E.png
but when I trim with a West or East gravity (which happens to be what I'd want), I get the same result as South (ie, the top is trimmed), while North (or South) is doing the expected result.
*updated* I want to automatically trim the right side of
http://i.imgur.com/oEZ3N.png
Re: trimming on one side only works on top and bottom.
Posted: 2012-02-19T14:01:29-07:00
by fmw42
What exactly do you want to do? Which sides do you want to trim and how much? Can you post a link to your input image?
-splice adds rows or columns and does not remove them. You need to use either -shave or -chop if you know exactly how much to trim. Otherwise, I would need to see your image to help you with -trim.
Re: auto-trimming on one side only works on top and bottom.
Posted: 2012-02-19T14:14:18-07:00
by fmw42
Do you want to trim the transparency only on the right side of oEZ3N.png. Why not all around?
This works for me.
convert oEZ3N.png -gravity west \
-background white -splice 5x0 \
-background black -splice 5x0 \
-trim +repage \
-gravity west -chop 5x0 \
oEZ3N_trim_west.gif
Re: auto-trimming on one side only works on top and bottom.
Posted: 2012-02-19T14:24:27-07:00
by ange4771
basically I want to merge the complete picture, ie merge oEZ3N.png with
http://i.imgur.com/lIztt.png on its right.
but if I just -trim all sides of both pictures, then 'convert +append' them, they're not perfectly aligned - I guess it's because their vertical start (of non transparency) is different, so I wanted to remove the right of oEZ3N.png and the left of lIztt.png before +appending them, then auto-trimming the merge
Re: auto-trimming on one side only works on top and bottom.
Posted: 2012-02-19T14:35:01-07:00
by fmw42
Try this
convert \( oEZ3N.png -gravity west \
-background white -splice 5x0 \
-background black -splice 5x0 \
-trim +repage \
-gravity west -chop 5x0 \) \
\( lIztt.png -gravity east \
-background white -splice 5x0 \
-background black -splice 5x0 \
-trim +repage \
-gravity east -chop 5x0 \) \
-background none -gravity north +append \
result.png
Re: auto-trimming on one side only works on top and bottom.
Posted: 2012-02-19T14:53:37-07:00
by ange4771
I see my mistake now - one of the splice was wrong. Thanks !
your command line gives almost a perfect result, except that there is a transparent line right in the middle - yet -trim should have removed that, right?
Re: auto-trimming on one side only works on top and bottom.
Posted: 2012-02-19T16:09:22-07:00
by fmw42
ange4771 wrote:I see my mistake now - one of the splice was wrong. Thanks !
your command line gives almost a perfect result, except that there is a transparent line right in the middle - yet -trim should have removed that, right?
Only if it was perfectly transparent. If not then no, unless you add -fuzz XX%. Apparently the transition between the image and transparent background is anti-aliased or there was some resizing that mixed image with transparency. This mixing can possibly come for example if this was generated with PS background transparency or with an anti-aliased alpha channel.
OK, -fuzz 50% does not seem to help for me. So you have to chop one column on each image.
try
convert \( 1oEZ3N.png -gravity west \
-background white -splice 5x0 \
-background black -splice 5x0 \
-trim +repage \
-gravity west -chop 5x0
-gravity east -chop 1x0 \) \
\( 1lIztt.png -gravity east \
-background white -splice 5x0 \
-background black -splice 5x0 \
-trim +repage \
-gravity east -chop 5x0
-gravity west -chop 1x0 \) \
-background none -gravity north +append \
1result.png