Page 1 of 1

Adding "outer glow" to a PNG with transparent background

Posted: 2016-02-17T11:08:10-07:00
by Marcesh
Hi guys,

i have a few thousand transparent png product images
which i would need to add a background and an outer glow to. is this possible with ImageMagick and how would the convert command be?

This is what I have
Image

This is what it should be
Image

even better if the background could be filled with a seamless texture from an jpg file..

thanks for your help in advance

Re: Adding "outer glow" to a PNG with transparent background

Posted: 2016-02-17T11:35:48-07:00
by snibgo
Marcesh wrote:i have a few thousand transparent png product images...
So why didn't you supply one? Instead, you supply an opaque example that has already been flattened against a chequer background. This means we can't experiment to work out an exact solution.

But an outline solution would be: extract the alpha, and blur. This would give a "glow" mask, but might need tweaking. Composite the original over that. Then flatten against a gray background, or whatever colour or other image you want.

Please also state the version of IM you use, and platform.

Re: Adding "outer glow" to a PNG with transparent background

Posted: 2016-02-18T09:31:48-07:00
by Marcesh
sorry my mistake

here's the png with transparency
Image

I'm using ImageMagick 6.8.6-9

Re: Adding "outer glow" to a PNG with transparent background

Posted: 2016-02-18T10:20:16-07:00
by snibgo
This is very close to your desired result. Windows BAT syntax.

Code: Select all

convert ^
  2lllxlv.png ^
  ( +clone ^
    -alpha extract ^
    -blur 0x10 ^
    -level 0,50%% ^
    -background White ^
    -alpha Shape ^
    +write g.png ^
  ) ^
  -compose DstOver -composite ^
  -background gray(42%%) ^
  -compose Over -layers flatten ^
  a.png
That gives a 42% gray background. If instead you want an image as background then ...

Code: Select all

convert ^
  2lllxlv.png ^
  ( +clone ^
    -alpha extract ^
    -blur 0x10 ^
    -level 0,50%% ^
    -background White ^
    -alpha Shape ^
    +write g.png ^
  ) ^
  -compose DstOver -composite ^
  your_background.jpg ^
  -compose DstOver -composite ^
  a2.png
EDIT: My commands include "+write g.png". They are for debugging (so you can sse just the "glow"). They can be removed when you are happy with the commands.

Re: Adding "outer glow" to a PNG with transparent background

Posted: 2016-02-18T18:04:49-07:00
by Marcesh
thank you so so much! i would never have figured out this complex command

Re: Adding "outer glow" to a PNG with transparent background

Posted: 2016-03-06T05:43:47-07:00
by paleshadow123
snibgo wrote:This is very close to your desired result. Windows BAT syntax.

Code: Select all

convert ^
  2lllxlv.png ^
  ( +clone ^
    -alpha extract ^
    -blur 0x10 ^
    -level 0,50%% ^
    -background White ^
    -alpha Shape ^
    +write g.png ^
  ) ^
  -compose DstOver -composite ^
  -background gray(42%%) ^
  -compose Over -layers flatten ^
  a.png
That gives a 42% gray background. If instead you want an image as background then, and it is not about being in that ... If you see below for the info because when they convert it, it might look different and some might try this code and it works successfully.

Code: Select all

convert ^
  2lllxlv.png ^
  ( +clone ^
    -alpha extract ^
    -blur 0x10 ^
    -level 0,50%% ^
    -background White ^
    -alpha Shape ^
    +write g.png ^
  ) ^
  -compose DstOver -composite ^
  your_background.jpg ^
  -compose DstOver -composite ^
  a2.png
EDIT: My commands include "+write g.png". They are for debugging (so you can sse just the "glow"). They can be removed when you are happy with the commands.
This is awesome work. Looked up your page particularly your canny edge detection. Really robust code there but get's the job done. Will you be expanding on it and polish it up even more, if that's even possible? Great stuff though.

Re: Adding "outer glow" to a PNG with transparent background

Posted: 2016-03-06T05:56:54-07:00
by snibgo
I often make small edits to existing pages. I have about 30 new pages in preparation.

Re: Adding "outer glow" to a PNG with transparent background

Posted: 2019-07-24T21:35:17-07:00
by hlynn
Should this work with newer versions of Image Magick. I'm using 7.0.8-23 and it just creates a dark border around the image. Has something changed?

Re: Adding "outer glow" to a PNG with transparent background

Posted: 2019-07-24T22:12:35-07:00
by fmw42
It works for me on IM 7.0.8.56 Q16 Mac OSX in Unix form

Code: Select all

magick -limit thread 1 \
2lllxlv.png \\
2lllxlv.png \
\( +clone \
-alpha extract \
-blur 0x10 \
-level 0,50% \
-background White \
-alpha Shape \
+write g.png \) \
-compose DstOver -composite \
-background "gray(42%)" \
-compose over -layers flatten \
a.png
Except there is a bug in OpenMP that is being attended to for the next release. So my result has some noise scattered about. But if I add (as I have) -limit thread 1, it fixes the issue until the fix is provided.

Please always provide your platform? Your version is rather old and I would suggest you upgrade as bugs are still being fixed.