Page 1 of 1

[SOLVED] Added drop shadow - can't see the shadow in Gimp

Posted: 2012-10-11T07:01:59-07:00
by rossmcm
I have added drop shadow to a PNG file with

Code: Select all

convert.exe a.png ( +clone -background black -shadow 80x3+5+5 ) ^
   -compose DstOver -composite   a_shadow.png
and I can't see the shadow with Gimp or IrfanView - although it does show in the Windows explorer thumbnail (and here).

What gives (really a Gimp question I suppose)?

a.png Image
a_shadow.png Image

Re: Added drop shadow - can't see the drop shadow with Gimp

Posted: 2012-10-11T13:21:33-07:00
by indiego
I had similar experiences with Gimp and several image viewers. The problem is not the png itself (checked with tweakpng), but that those viewers don't handle the indexed pngs (256colors) right. To get rid of the indexed (paletted) png save it with the prefix 'png32:'.
It can also be helpful to save a background color (e.g. white), so that some viewers don't show black only thumbnails of that graphic.
Sadly this seems to be a common problem.


This works here

Code: Select all

convert.exe a.png ( +clone -background black -shadow 80x3+5+5) ^
  -compose DstOver -composite -background white png32:a_shadow.png

Re: Added drop shadow - can't see the drop shadow with Gimp

Posted: 2012-10-11T13:43:59-07:00
by rossmcm
Brilliant. Fixed. Thank you. -

As a matter of interest, you don't know exactly what the parameters for the -shadow option are, do you (i.e. the "80x3+5+5")?

R

Re: Added drop shadow - can't see the drop shadow with Gimp

Posted: 2012-10-11T13:52:24-07:00
by Bonzo
The -shadow options are here along with all the other options: http://www.imagemagick.org/script/comma ... php#shadow

Re: Added drop shadow - can't see the drop shadow with Gimp

Posted: 2012-10-11T14:07:55-07:00
by fmw42
see also
http://www.imagemagick.org/Usage/blur/#shadow

first is the opacity
second is the gaussian blur sigma
x and y are the shadow offsets in pixels

Re: Added drop shadow - can't see the drop shadow with Gimp

Posted: 2012-10-11T16:44:34-07:00
by anthony
rossmcm wrote:

Code: Select all

convert.exe a.png ( +clone -background black -shadow 80x3+5+5 ) ^
   -compose DstOver -composite   a_shadow.png
[/img]

The above example is WRONG....
The shadow will be offset by 10 pixels rather than 5. The problem is shadow generates a 'layer image' with a offset. However direct composition is a much lower level operator and does not use layer offsets.

The above composed the image without regard to the layering offsets that shadow generated, or the enlarged image shaodw generates and as such the shadow is in the wrong position, and gets clipped by the original images bounds.

See Shadowing examples for correct usage and a more detailed explanation.
http://www.imagemagick.org/Usage/blur/#shadow

Remember shadows tend to extend in all directions, not just the expected direction (due to the blur).

Re: Added drop shadow - can't see the drop shadow with Gimp

Posted: 2012-10-11T19:28:56-07:00
by rossmcm
Hi Anthony,

Thanks for your reply. Your explanation about the offsets is noted, however, I was adjusting the shadow position by trial and error anyway. For the image I was dealing with as an example (Image) I wanted a shadow that looked like this: Image

The IM command that I needed to do the trick was:

Code: Select all

convert ^
  "a.png" ^
  ^( +clone -background gray -shadow "80x1+2+2" ^) ^
  -compose DstOver -composite "png32:b.png"
My main requirement was that the resulting image not be increased in size to account for any blurring (I had already provided a transparent guard boundary in the original), that the blurred part be truncated at the original image boundary, and the original image was not to be offset. The above IM command accomplishes that, and inspection of the result seems to show that the shadow is offset by +2, +2 (white background added for clarity).

a.png Image
b.png Image

Re: [SOLVED] Added drop shadow - can't see the shadow in Gim

Posted: 2012-10-11T21:08:54-07:00
by anthony
Okay, preserve the original image size that is fine. But I am just warning that the +X+Y from the -shadown operator would not be understood by -composite (too low a level).

Two solutions to preserving the original size...

Code: Select all

   -background none -compose DstOver -flatten
OR

Code: Select all

   -geometry +X+Y -compose DstOver -composite
The start point for -geometry +X+Y would be -S-S where S is 2*sigma used for the blur, then add to that the offset.

In your case sigma was 1 and your offset was zero making geometry +0+0 which is the default -- you are lucky it came out correct. But if you change the blur sigma, or want to change your offset, you will need a -geometry setting...

Simply put, the first 'layer' method above is easier, correct, and offset can be adjusted as intended.

Re: [SOLVED] Added drop shadow - can't see the shadow in Gim

Posted: 2012-10-11T21:38:08-07:00
by rossmcm
hmmm.. I think I see. So the correct command line would be...?

TIA,
R

Re: [SOLVED] Added drop shadow - can't see the shadow in Gim

Posted: 2012-10-11T23:49:42-07:00
by anthony
Something like... (to preserve the original image size).

Code: Select all

convert.exe a.png ( +clone -background black -shadow 80x2+2+2 ) ^
     -background none -compose DstOver -flatten  a_shadow.png

I'll add this to the IM examples, give it a bit of time.

Re: [SOLVED] Added drop shadow - can't see the shadow in Gim

Posted: 2012-10-12T01:51:17-07:00
by rossmcm
Now that's service. Thanks Anthony.

R