Help with outer glow and alpha mask

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
Greywey
Posts: 6
Joined: 2011-11-03T00:10:24-07:00
Authentication code: 8675308

Help with outer glow and alpha mask

Post by Greywey »

Hi I have two problems. First, I'm trying to make a purple outer glow. Every time I look up "glow" its not what I'm looking for. I also tried making a larger centered purple shadow but it's not right. My second problem is that I need to make an alpha mask. Where any pixel alpha=0 is black, and everything else is white. Thanks very much for any help.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Help with outer glow and alpha mask

Post by fmw42 »

More information about your image would be helpful or a link to your image?

Nevertheless, see http://www.imagemagick.org/Usage/fonts/ for examples of such things done to text images.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Help with outer glow and alpha mask

Post by anthony »

More specifically look at the Neon sign example at the very bottom
http://www.imagemagick.org/Usage/fonts/#neon
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Greywey
Posts: 6
Joined: 2011-11-03T00:10:24-07:00
Authentication code: 8675308

Re: Help with outer glow and alpha mask

Post by Greywey »

Hi thanks very much. I actually read those articles already, they were the closest thing to what I needed. But, since they deal with fonts they were hard to use. My image is just an irregular transparent shape, a yellow star. I did manage to get my glow working thanks very much! But I'm having a hard time with the alpha mask. I need the opaque parts white over a black background with no alpha, any hints? Thanks very much.

My glow:
convert.exe a.png ( +clone -background #ff80ff -shadow 100x1+0+0 -channel A -level 0,100% -blur 0x2 ) -compose DstOver -gravity center -composite a_glow.png

My alpha mask, almost there, but the alpha channel is still there at the end?
convert.exe a.png ( +clone -background white -shadow 100x0+0+0 -channel A -level 0,100% ) -compose SrcOver -gravity center -composite a_mask.png
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Help with outer glow and alpha mask

Post by anthony »

Give use your input image, and your results. Then let us know what you want.

You can use a cloud hosting service to store images to use. Such as 'dropbox'.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Greywey
Posts: 6
Joined: 2011-11-03T00:10:24-07:00
Authentication code: 8675308

Re: Help with outer glow and alpha mask

Post by Greywey »

Hi, I've uploaded "star.png" which is the source image, and I made samples of the output I need in "star_glow.png" and "star_mask.png". The mask should have no alpha. Thanks very much!

http://drillion.com/star.zip
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Help with outer glow and alpha mask

Post by anthony »

The mask is not needed, as it is part of original image. The shadow color looks to be "DeepPink"

The technique is explained in IM Examples, Shadow Images, and more specifically, Shadow outlines
http://www.imagemagick.org/Usage/blur/#shadow_outline

The tricky part however is to realise that a shadow blur works both inward and outward.
That when overlaying the glow, the shadow is 50% transparent. You want it opaque at the very edge.
This currently needs some extra processing.

Here is the solution...

Code: Select all

  convert star.png  \
              \( +clone -background DeepPink -shadow 100x10+0+0 \
                 -channel A -level 0,50% +channel \
              \) -background none -compose DstOver -flatten \
              star_glow.png
Note I used a compose DstOver with Flatten as the shape already has enough space for the glow.
If it did not I would have just used -layers merge +repage instead.



FUTURE:
I am thinking to modify the -shadow operator so that it will accept larger values than 100% for shadow transparency. That is allow the use of -shadow 200x10+0+0 in the above to
do the correct multiplication of the alpha channel after the blur, and removing the need for extra -level operations. Currently this is not the case.

I am also thinking of treating a negative transparency that negates the shape before creating the shadow image, so as to allow the creating of 'inner shadows' for bordering shapes.

For IMv7 I am thinking of making the -shadow operator to automatically apply shadows to the given image (in the appropriate way, with enlargement -- no clone needed), while making +shadow simply create shadows (as it currently does) for DIY shadow effects. This last must be a IMv7 addition due to the simplified handling of the -shadow operator. Otherwise the change would break many scripts.

Anyone else have thoughts on these changes.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Greywey
Posts: 6
Joined: 2011-11-03T00:10:24-07:00
Authentication code: 8675308

Re: Help with outer glow and alpha mask

Post by Greywey »

Thanks that glow is much better!
Post Reply