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

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
User avatar
rossmcm
Posts: 28
Joined: 2012-07-26T06:10:38-07:00
Authentication code: 15
Location: Auckland, NZ

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

Post 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
Last edited by rossmcm on 2012-10-11T20:26:18-07:00, edited 2 times in total.
indiego
Posts: 75
Joined: 2010-10-16T06:35:10-07:00
Authentication code: 8675308

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

Post 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
User avatar
rossmcm
Posts: 28
Joined: 2012-07-26T06:10:38-07:00
Authentication code: 15
Location: Auckland, NZ

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

Post 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
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

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

Post by Bonzo »

The -shadow options are here along with all the other options: http://www.imagemagick.org/script/comma ... php#shadow
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

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

Post 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).
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
rossmcm
Posts: 28
Joined: 2012-07-26T06:10:38-07:00
Authentication code: 15
Location: Auckland, NZ

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

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

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

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
rossmcm
Posts: 28
Joined: 2012-07-26T06:10:38-07:00
Authentication code: 15
Location: Auckland, NZ

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

Post by rossmcm »

hmmm.. I think I see. So the correct command line would be...?

TIA,
R
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

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

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
rossmcm
Posts: 28
Joined: 2012-07-26T06:10:38-07:00
Authentication code: 15
Location: Auckland, NZ

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

Post by rossmcm »

Now that's service. Thanks Anthony.

R
Post Reply