Page 1 of 1

possible bug with -bordercolor

Posted: 2010-05-18T10:44:38-07:00
by fmw42
IM 6.6.1-10 Q16 Mac OSX Tiger

Is it possible to put a non-transparent border around a transparent image (without appending)?

These do not seem to work as the whole transparent area become red rather than just the border.

convert logo: -resize 50% -transparent white -bordercolor red -border 10 tmp.png

convert logo: -resize 50% -transparent white -channel rgba -background none -bordercolor "rgba(255,0,0,1)" -border 10 tmp.png


Am I misunderstanding how -border works with transparent images or is this a bug?

Re: possible bug with -bordercolor

Posted: 2010-05-18T11:30:43-07:00
by magick
Add -compose copy to your command line.

Re: possible bug with -bordercolor

Posted: 2010-05-18T11:51:39-07:00
by fmw42
thanks. yes this works.

convert logo: -resize 50% -transparent white -compose copy -bordercolor red -border 10 tmp.png

I had tried resetting -compose over rather than -compose copy.

Re: possible bug with -bordercolor

Posted: 2010-05-18T20:23:02-07:00
by anthony
See IM Examples Border
http://www.imagemagick.org/Usage/crop/#border
The same problem is also in Frame, Extent, and the layer methods Flatten, Mosaic and Merge,
for the same reasons. A background image is created and the operator then composes the image onto the background. -compose copy means copy the transparent pixels too!

Re: possible bug with -bordercolor

Posted: 2010-05-19T12:28:13-07:00
by fmw42
adding -compose copy does not work in montage

convert logo: -resize 50% -transparent white logo2t.png

montage -texture pattern:checkerboard \
logo2t.png logo2t.png logo2t.png logo2t.png \
-compose copy -bordercolor red -border 10 \
-geometry +10+10 -tile 2x2 logo2t_montage1.png

Image

transparency is turned to white and not checkerboard

nor does

montage -texture pattern:checkerboard \
\( logo2t.png -compose copy -bordercolor red -border 10 \) \
\( logo2t.png -compose copy -bordercolor red -border 10 \) \
\( logo2t.png -compose copy -bordercolor red -border 10 \) \
\( logo2t.png -compose copy -bordercolor red -border 10 \) \
-geometry +10+10 -tile 2x2 logo2t_montage2.png

Image

The following almost does what I want, but the first image has a gray border and not red.


montage -background none \
\( -size 320x240 pattern:checkerboard logo2t.png -compose over -composite -bordercolor red -border 10 \) \
\( -size 320x240 pattern:checkerboard logo2t.png -compose over -composite -bordercolor red -border 10 \) \
\( -size 320x240 pattern:checkerboard logo2t.png -compose over -composite -bordercolor red -border 10 \) \
\( -size 320x240 pattern:checkerboard logo2t.png -compose over -composite -bordercolor red -border 10 \) \
-geometry +10+10 -tile 2x2 logo2t_montage3.png

Image

How can I modify this last one to get the red border on the first image?

Re: possible bug with -bordercolor

Posted: 2010-05-19T21:47:19-07:00
by anthony
fmw42 wrote:adding -compose copy does not work in montage
Actually it is worse that that!

-border is now a special montage setting!! Just like -frame and -tile. Its value is simple saved away for future use rather than acted on immediately. I am not certain when this changed though, sometime about IM v6.1.0

See Montage, Border Decoration
http://www.imagemagick.org/Usage/montage/#border

It was done so that border could be added AFTER images are resized. Something which I can understand. However it currently does not play nicely with the montage -frame setting, though both could conceivably work together (with a border being added before the frame).

This change caught me by surprise as well, as my gif_anim_montage script previously made use of -border within a montage. Essentially that script is a montage that displays virtual canvas information, such as used by GIF Animations and experimental segmentation output.

Re: possible bug with -bordercolor

Posted: 2010-05-19T21:53:57-07:00
by fmw42
Anthony,

Do you see a workaround for why the first image has a gray border and the rest are correctly red?

Fred

Re: possible bug with -bordercolor

Posted: 2010-05-20T18:19:18-07:00
by anthony
As -border is only being cached and not applied.

For example. in montage you can set border color AFTER the '-border' setting

Code: Select all

montage rose: rose: rose: rose: -border 20 -bordercolor red -geometry +10+10 show:
All roses had a red border!

As this is a new "montage setting" I can only see this as a bug in the montage handling of border.

My solution to my problem with -border was to pre-process images using convert rather than montage.

NOTE: you can also use -extent to add a border, but specify the final size rather than border with!
That is not a special montage option so will work fine!

Code: Select all

montage -gravity center \
     \( rose: -background red -extent 100x100 \) \
     \( rose: -background blue -extent 100x100 \) \
     \( rose: -background green -extent 100x100 \) \
     \( rose: -background white -extent 100x100 \) \
     -background None -geometry +10+10 show:
Note I needed to reset the -background color as it is a montage setting!
Actually both -border and -bordercolor is also a montage setting!

You should not get two different border colors, unless something is wrong!

Re: possible bug with -bordercolor

Posted: 2010-05-20T19:36:20-07:00
by fmw42
Interesting:

This does not work with -bordercolor in the parens as the first image gets a gray border as shown above:

montage \
\( -size 320x240 pattern:checkerboard logo2t.png -compose over -composite -bordercolor red -border 10 \) \
\( -size 320x240 pattern:checkerboard logo2t.png -compose over -composite -bordercolor red -border 10 \) \
\( -size 320x240 pattern:checkerboard logo2t.png -compose over -composite -bordercolor red -border 10 \) \
\( -size 320x240 pattern:checkerboard logo2t.png -compose over -composite -bordercolor red -border 10 \) \
-background none -geometry +10+10 -tile 2x2 logo2t_montage3.png


But this does work with -extent and all four images have a red border:

montage \
\( -size 320x240 pattern:checkerboard logo2t.png -compose over -composite -gravity center -background red -extent 340x260 \) \
\( -size 320x240 pattern:checkerboard logo2t.png -compose over -composite -gravity center -background red -extent 340x260 \) \
\( -size 320x240 pattern:checkerboard logo2t.png -compose over -composite -gravity center -background red -extent 340x260 \) \
\( -size 320x240 pattern:checkerboard logo2t.png -compose over -composite -gravity center -background red -extent 340x260 \) \
-background none -geometry +10+10 -tile 2x2 logo2t_montage4.png

AND I just found out that this also works to give each image a red border by placing -bordercolor out of the parens

montage -bordercolor red \
\( -size 320x240 pattern:checkerboard logo2t.png -compose over -composite -border 10 \) \
\( -size 320x240 pattern:checkerboard logo2t.png -compose over -composite -border 10 \) \
\( -size 320x240 pattern:checkerboard logo2t.png -compose over -composite -border 10 \) \
\( -size 320x240 pattern:checkerboard logo2t.png -compose over -composite -border 10 \) \
-background none -geometry +10+10 -tile 2x2 logo2t_montage5.png

Re: possible bug with -bordercolor

Posted: 2010-05-20T21:56:53-07:00
by anthony
I repeat yet again!!!

In "montage" -border is useless except as a final montage specific setting. In montage it is not an operator, and its argument is only saved for later use (just like -frame in montage).

Using it in parenthesis or anywhere but at the end is useless!!!!!

Removing them all but at the end as a final setting....

Code: Select all

montage \
\( -size 320x240 pattern:checkerboard logo2t.png -compose over -composite  \) \
\( -size 320x240 pattern:checkerboard logo2t.png -compose over -composite \) \
\( -size 320x240 pattern:checkerboard logo2t.png -compose over -composite  \) \
\( -size 320x240 pattern:checkerboard logo2t.png -compose over -composite  \) \
-background none -geometry +10+10 -tile 2x2 \
-border 10 -bordercolor red  logo2t_montage3.png
This works perfectly. I do not know why it is failing in parenthesis as -border is just a setiing.

NOTE the order of -border and -bordercolor does not matter, as in montage BOTH are just settings that are saved for later use.

Most likely explanation for the previous failing is that the parenthesis handler is designed for "convert" and nor "montage" where it has extra settings that are only used at the very end, and this is confusing things. It may be that it is applying -border in some instances as a operator, when in montage it is only a setting.

Re: possible bug with -bordercolor

Posted: 2010-05-21T06:04:33-07:00
by magick
The montage -border option sets the border width for the montage layout manager. If we apply the border instead to each image, when the layout manager scales the image to present as a tile on the montage canvas we could get different sized borders. The solution of course is two different options but we can't change the meaning now since folks have depended on -border affecting the layout manager for years now. The solution is to use context. Since parenthesis are relatively new we could use -border outside parens as a montage layout manager setting and anything inside parens as the normal -border behavior.

Re: possible bug with -bordercolor

Posted: 2010-05-21T06:11:46-07:00
by snibgo
Not forgetting, of course, that parentheses can be nested.

Re: possible bug with -bordercolor

Posted: 2010-05-21T09:14:24-07:00
by fmw42
Anthony wrote:In "montage" -border is useless except as a final montage specific setting. In montage it is not an operator, and its argument is only saved for later use (just like -frame in montage).

Using it in parenthesis or anywhere but at the end is useless!!!!!
Thanks. It has taken a while to sink in as to what you meant.