3 Sided Shadow

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
netnichols

3 Sided Shadow

Post by netnichols »

I actually posted something similar back in April, but that post (and my old user) seem to be gone. Anyway...

Does anyway have a single command for adding a 3 sided drop shadow? I have an unbelievably ugly solution, but feel sure magick users with more skills than me could do better.

Feel free to laugh at my code, I'm sure it's overly engineered and the completely wrong way to go about things with imagemagick... I'm a java guy after all...

Code: Select all

function addShadow {
	OW=$(identify -format "%w" $1)
	OH=$(identify -format "%h" $1)

	convert $1 \( +clone -background $col -shadow $FILTER_R \) +swap -background none -mosaic /tmp/sr.png

	NW=$(identify -format "%w" /tmp/sr.png)
	NH=$(identify -format "%h" /tmp/sr.png)
	WD=$[$NW - $OW]

	convert -page +$WD+0 $1 \( +clone -background $col -shadow $FILTER_L \) +swap -background none -mosaic /tmp/sl.png

	WS=$[$WD + $WD]
	WR=$[$OW - $WS]

	convert /tmp/sl.png -gravity West -crop $WS\x$NH+0+0 /tmp/tl.png
	convert /tmp/sl.png -gravity West -crop $WR\x$NH+$WS+0 /tmp/tm.png
	convert /tmp/sr.png -gravity East -crop $WS\x$NH+0+0 /tmp/tr.png
	convert -depth 8 +append /tmp/tl.png /tmp/tm.png /tmp/tr.png $1
	rm /tmp/tl.png /tmp/tm.png /tmp/tr.png
}
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: 3 Sided Shadow

Post by anthony »

netnichols wrote:Does anyway have a single command for adding a 3 sided drop shadow? I have an unbelievably ugly solution, but feel sure magick users with more skills than me could do better.
What is a 3 sided drop shadow????
A simple final example image would have been good.

Is it like 'thickness', see...
http://www.imagemagick.org/Usage/thumbnails/#thickness
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
netnichols

Re: 3 Sided Shadow

Post by netnichols »

anthony wrote:What is a 3 sided drop shadow????
A simple final example image would have been good.
Sorry... I lost track of this thread, but here are some examples:

2 Sided Shadow:
Image

3 Sided Shadow: (using function above)
Image
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: 3 Sided Shadow

Post by anthony »

I see...

The -shadow function as used by IM is actually a blurred shadow, which blurs in ALL directions then offsets the result by the user supplied amount.

You could say, using your defination, its a 4 sided shadow.

In fact there are examples of this in IM examples (as soft outlining effect)
http://imagemagick.org/Usage/convolve/#shadow
Look for the title 'shadow outlines' in that section.

For a 3 side shadow, what I would do is just shadow it normally and offset the shadow straight downward, rather than diagonally left or right. If you can enlarge the shape being shadowed slightly, or merge two shadows, or even so some other post processing of the shadow, you can generate a stronger 3 sided effect (the outline shaodw example does the latter using a -channel restricted -evaluate ).
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
netnichols

Re: 3 Sided Shadow

Post by netnichols »

Thanks Anthony, that helped a lot. It took a little tweaking, but I've got something that produces very similar results to my messy function above:

Code: Select all

convert pic.png \( +clone -background black -shadow 75x5+0+0 -channel A -evaluate multiply 1 +channel \) +swap +repage -gravity center -geometry -0-4 -composite pic-shadow.png
And it's easy to tweak it further.

Thanks again.

As a side note, I couldn't get the example using "-layers merge" to work for me... it always complained of "convert: UnrecognizedLayerMethod `merge'." I'm using version 6.3.6 installed with MacPorts.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: 3 Sided Shadow

Post by anthony »

The -layers merge is one of the most recent additions. basically to allow flatten/mosaic operations on images with negative offset positions, which is likely to happen as Image distortion progresses to the point of doing panarama mosaics. It certainally makes shadowing easier as this can also generate negative offsets.

MacPorts may need to update to a newer version for its releases soon.

I really wish I can generate APT packaged versions for ubuntu, which I have been trialling. as it is I have to compile and install a personal IM version in my own home. -- Sory I am ranting :lol:
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply