Page 1 of 1
IM7.0.5-5 Problem with border and transparent canvas...
Posted: 2017-04-26T11:32:01-07:00
by GeeMack
Using IM 7.0.5-5 HDRI on Windows 10 64 and running this command...
Code: Select all
magick -size 100x100 xc:none -bordercolor red -border 2 test_v7.png
... creates a solid red square, which is pretty obviously incorrect and is causing a problem for some of my scripts. It should put a red border around a transparent canvas. The same command using IM 6.9.7-6...
Code: Select all
convert -size 100x100 xc:none -bordercolor red -border 2 test_v6.png
... works as expected to produce a transparent square with a red border.
The square gets filled with whatever is set as the "-bordercolor".
The problem occurs if I create the transparent canvas by any method like "xc:none" or "xc:transparent" or "xc:#00000000".
It also occurs with a semi-transparent colored canvas made like this "xc:#FFFFFF80". The border color is showing behind the semi-transparency.
Re: IM7.0.5-5 Problem with border and transparent canvas...
Posted: 2017-04-26T12:50:30-07:00
by snibgo
The functionality of "-border" has changed a bit between versions, though the documentation hasn't:
It generates an image of the appropriate size colors by the current -bordercolor before overlaying the original image in the center of this net image.
So, "-bordercolor red -border 2" should create an opaque red image 2 pixels larger than the input, and composite the input over this. As your input is "-size 100x100 xc:none", the result should be 102x102 opaque red pixels. You might think this is "pretty obviously incorrect", but it is the documented behaviour.
Re: IM7.0.5-5 Problem with border and transparent canvas...
Posted: 2017-04-26T12:51:17-07:00
by fmw42
I can confirm the issue on Mac OSX Sierra using IM 7.0.5.5. But it works fine using IM 7.0.5.4.
Re: IM7.0.5-5 Problem with border and transparent canvas...
Posted: 2017-04-26T13:04:01-07:00
by fmw42
Using IM 6.9.8.4 it produces the same fully red image. But using IM 6.9.8.3, it produces the transparent image with the red border.
I am not sure why this behavior is changing. It may correspond to the current code.
Perhaps the IM developers can explain why the change.
Nevertheless, you can get it to work to have the transparent inside, if you add -compose copy before -bordercolor red -border 2 in both the current IM 6 and IM 7. This just may have to be the way to do it from here on, if there is a good reason for the changed behavior.
Code: Select all
magick -size 100x100 xc:none -compose over -bordercolor red -border 2 test_v7.png
Re: IM7.0.5-5 Problem with border and transparent canvas...
Posted: 2017-04-26T13:07:15-07:00
by snibgo
I don't use "-border" with non-opaque images without "-compose" because the behaviour is unstable between versions. In some versions, it works as documented. Then someone doesn't read the documentation, so it is changed to work "as expected".
If you want "Copy" instead of "Over", as Fred says, use "-compose Copy".
Re: IM7.0.5-5 Problem with border and transparent canvas...
Posted: 2017-04-26T13:12:56-07:00
by fmw42
On second thought, snibgo is likely correct. The code may have always intended to work to give the current all red result. Perhaps it was tweaked before at various times to preserve the transparent insides. So it may now have been set back to the way it was intended. And going forward, the use of -compose copy should properly be used to handle adding opaque borders to transparent images.
Re: IM7.0.5-5 Problem with border and transparent canvas...
Posted: 2017-04-26T14:00:14-07:00
by GeeMack
fmw42 wrote: ↑2017-04-26T13:04:01-07:00[...] if there is a good reason for the changed behavior.
I'd be very curious to know what might be considered a good reason. Is there anyone anytime who would ever use "-border 2" with the intent to fill the bounded space with the border color?
Re: IM7.0.5-5 Problem with border and transparent canvas...
Posted: 2017-04-26T14:19:53-07:00
by snibgo
I get a bit lost what is meant by the "changed" behaviour. It's broken (ie not as documented) in v7.0.3-5, where it forced the behaviour of "-compose Copy". I think it has been fixed since then.
GeeMack wrote:Is there anyone anytime who would ever use "-border 2" with the intent to fill the bounded space with the border color?
You can see examples of this use of "-border" at
http://www.imagemagick.org/Usage/crop/#border , which uses IM 6.6.9-7. IM's "-border" has always worked as documented (apart from occasional glitches).
The thing to remember is that "-border" doesn't simply add a border. By default (unless "-compose XX" is used) it also makes the image opaque.
Re: IM7.0.5-5 Problem with border and transparent canvas...
Posted: 2017-04-26T16:21:52-07:00
by anthony
In the second set of examples of Border...
http://www.imagemagick.org/Usage/crop/#border
I go though a number of different compose methods, including Copy.
And the very next example (third one) that is a specific one for Copy!
Code: Select all
convert star.gif -bordercolor LimeGreen -compose Copy \
-border 5 star_border_copy.gif
NOTE that
-frame also does the same thing. The image background is filled with the border color, then the frame is drawn around that. However in that case you can simply set the
-bordercolor None to prevent it from filling it in, BUT you can also use
-compose Copy as well.
Re: IM7.0.5-5 Problem with border and transparent canvas...
Posted: 2017-04-26T19:33:56-07:00
by GeeMack
As always I appreciate everyone's help. I've been using a border around a transparent canvas to make crop marks for printing business cards, tickets, etc. When a recent version of IM started filling in my templates with the border color it seemed like something was wrong. The fix is simple enough. I should have RTFM.