Page 1 of 1

trim & make transparent (region)

Posted: 2017-06-24T14:39:33-07:00
by Lars-Daniel
Hi there,

I want to trim an image by a fuzzy border color (white to gray) and make the old border transparent. Works fine with this:

Code: Select all

convert -fuzz 50% -trim input.png -background transparent -flatten output.png
Now I'd like to take 10% from "-gravity north" and also want to turn the white color to transparent. Actually, this doesn't work, since region is buggy in v7: https://www.imagemagick.org/discourse-s ... =3&t=32212

Is it possible to cut out 10% from the top, make it transparent and replace the part of the original image? I wasn't able to replace it, I was only able to overlay it ... but of course, this doesn't work :)

Example image (the part aboth the map "Field Papers" should be turned to transparent): http://imgur.com/a/1FG7T

Best,
Lars-Daniel

Re: trim & make transparent (region)

Posted: 2017-06-24T15:13:29-07:00
by fmw42
Please always provide your IM version and platform, since syntax differs. Do you want to trim first and then cut out 10% from the top and make white transparent. I am confused. Please list the exact steps you want.

Your syntax is not truly proper though IM 6 is forgiving. You should read your input first, then settings, then operators, then the output:

Code: Select all

convert input.png -fuzz 50% -trim +repage -background transparent -flatten output.png
If you just want to replace the top 10% with transparency (chop 10% off and splice 10% transparent back), then try (Unix syntax for IM 6).

IM 6

Code: Select all

chopamt=`convert input.jpg -format "%[fx:0.1*h]" info:`
convert input.jpg -gravity north -chop 0x$chopamt -background none -splice 0x$chopamt result.png
IM 7

Code: Select all

magick input.jpg -set option:chopamt "%[fx:0.1*h]" -gravity north -chop "0x%[chopamt]" -background none -splice "0x%[chopamt]" result.png
If that is not what you want, please clarify further

Re: trim & make transparent (region)

Posted: 2017-06-24T15:22:23-07:00
by Lars-Daniel
fmw42 wrote: 2017-06-24T15:13:29-07:00 Your syntax is not truly proper though IM 6 is forgiving. You should read your input first, then settings, then operators, then the output:
Sorry, didn't know the syntax changed. Thanks for the hint, I'll read into that.[/quote]
fmw42 wrote: 2017-06-24T15:13:29-07:00convert input.png -fuzz 50% -trim +repage -background transparent -flatten output.png[/code]
I don't want to repage (see below), but I'll try to implement your other parts.
fmw42 wrote: 2017-06-24T15:13:29-07:00If that is not what you want, please clarify further
Actually, that's what I want. All the red colored part should be transparent: http://imgur.com/a/r5DPC

Re: trim & make transparent (region)

Posted: 2017-06-24T15:30:09-07:00
by fmw42
You can do this to change the pink to transparent.

Code: Select all

convert input.png -fuzz 10% -fill none -draw "matte 10,10 floodfill" result1.png
There are some red lines left. So for that you would likely need to shave or chop off those parts of the image.

See
http://www.imagemagick.org/Usage/draw/#matte
http://www.imagemagick.org/Usage/crop/#shave
http://www.imagemagick.org/Usage/crop/#chop

Re: trim & make transparent (region)

Posted: 2017-06-24T15:38:52-07:00
by Lars-Daniel
Sorry, this gives me:
convert: NonconformingDrawingPrimitiveDefinition `matte' @ error/draw.c/DrawImage/3269.

Re: trim & make transparent (region)

Posted: 2017-06-24T16:30:52-07:00
by fmw42
On IM 7, there are changes. That is why it is always a good idea to identify your IM version and platform. Try

Code: Select all

magick input.png -fuzz 10% -fill none -draw "alpha 10,10 floodfill" result.png
See some changes in http://imagemagick.org/script/porting.php#cli