auto-trimming on one side only works on top and bottom.

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
ange4771
Posts: 3
Joined: 2012-02-19T13:53:37-07:00
Authentication code: 8675308

auto-trimming on one side only works on top and bottom.

Post 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
Last edited by ange4771 on 2012-02-19T14:09:55-07:00, edited 2 times in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: trimming on one side only works on top and bottom.

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: auto-trimming on one side only works on top and bottom.

Post 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
ange4771
Posts: 3
Joined: 2012-02-19T13:53:37-07:00
Authentication code: 8675308

Re: auto-trimming on one side only works on top and bottom.

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: auto-trimming on one side only works on top and bottom.

Post 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
ange4771
Posts: 3
Joined: 2012-02-19T13:53:37-07:00
Authentication code: 8675308

Re: auto-trimming on one side only works on top and bottom.

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: auto-trimming on one side only works on top and bottom.

Post 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
Post Reply