IM7.0.5-5 Problem with border and transparent canvas...

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

IM7.0.5-5 Problem with border and transparent canvas...

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: IM7.0.5-5 Problem with border and transparent canvas...

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

Re: IM7.0.5-5 Problem with border and transparent canvas...

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

Re: IM7.0.5-5 Problem with border and transparent canvas...

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: IM7.0.5-5 Problem with border and transparent canvas...

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

Re: IM7.0.5-5 Problem with border and transparent canvas...

Post 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.
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: IM7.0.5-5 Problem with border and transparent canvas...

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: IM7.0.5-5 Problem with border and transparent canvas...

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: IM7.0.5-5 Problem with border and transparent canvas...

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

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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: IM7.0.5-5 Problem with border and transparent canvas...

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