drop shadow or similar effects

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
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

drop shadow or similar effects

Post by javismiles »

hi :)
what is the simplest way to do a drop shadow or similar effect to render a text as a PNG image so that when composited over different
backgrounds it stands out? could be a drop shadow effect or a stroke border around the text, is this possible to be done in a single command
when rendering a text as an image? hopefully using the :label command that im already using?

thank you very much
Jav :)
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

Re: drop shadow or similar effects

Post by javismiles »

i just found that i can do this
-shadow 50x1+10+10
to create a shadow

but the question is, can i render a text as image and add the shadow to it all in one single command?
thats what i would need, so that i could have the text+the shadow all together in a PNG output

if possible using :label but if not with draw annotate or any other,

thank u very much
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: drop shadow or similar effects

Post by fmw42 »

Yes, see hard and soft shadow examples at http://www.imagemagick.org/Usage/fonts
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

Re: drop shadow or similar effects

Post by javismiles »

yes it works,
its great
i just have one problem,
when i do a shadow that is blurred, say with a blur of x4 or x5, the resulting image because of the offset created
by the blur, moves in relation to the previous one

i read that repage can maybe be used to compensate for that offset but i dont understand how, any tips?
thank u
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

Re: drop shadow or similar effects

Post by javismiles »

i read that +repage is supposed to reset the offset, but it doesnt seem to work
in the latest version, other people saying the same, any tips?
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

Re: drop shadow or similar effects

Post by javismiles »

this is the command i use

convert -background none -fill #ffffff -font Arial -pointsize 100 -rotate 0 -gravity West label:"text" ( -clone 0 -background black -shadow 100x1+2+2 ) -reverse -background none -layers merge +repage result.png

it works great, but the resulting image moves with an offset from its previous position, i just need to eliminate that offset created by the Blur setting of the shadow

thank you very much
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: drop shadow or similar effects

Post by fmw42 »

This seems to work fine for me. I am not sure what offset you mean?


convert \( -background none -fill "#ffffff" -font Arial-Regular \
-pointsize 100 -gravity West label:"text" \) \
\( -clone 0 -background black -shadow 100x1+2+2 \) \
-reverse -background none -layers merge tmp.png

(note the quotes on #ffffff --- rgb and hex colors should be quoted)

-rotate 0 is unnecessary in this example

identify -verbose tmp.png
...
Page geometry: 167x118+0+0

No offset here


+repage is only needed if you add -trim as in Anthony's example. It is used to reset the virtual canvas which gets set by -crop or -trim.

What version of IM are you using. Perhaps upgrade to the latest.
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

Re: drop shadow or similar effects

Post by javismiles »

no, you see, i need to explain myself better

the problem is that when adding blur, the resulting image is larger than when you dont add blur

lets suppose i generate the text: hello, and i have it in position 100,100 within a larger canvas

then i recreate that text this time with a shadow that has a blur of x5
the resulting png of the text is larger and when staying at 100,100 within the larger canvas, the text offsets from the previous one,
it doesnt stay in the same place, this only happens with the blur because it makes the resulting image larger

im just trying to compensate for that
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

Re: drop shadow or similar effects

Post by javismiles »

by the way , i dont use quotes with the #ff0066 in the fill and it works great

the repage, i have eliminated it now, but i have the same problem still

when using blur, resulting image is larger
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

Re: drop shadow or similar effects

Post by javismiles »

im having another problem

when using Rotate mixed with shadow in that command, only the shadow rotates, not the image,
how could i solve this?

convert -background none -fill #ffffff -font Arial -pointsize 100 -rotate 90 -gravity West label:"text" ( -clone 0 -background black -shadow 100x1+2+2 ) -reverse -background none -layers merge result.png

thank u very much
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

Re: drop shadow or similar effects

Post by javismiles »

i have managed to do the rotate well now, just moving the rotate to the end of command

so only problem i have left is that the shadow that has blur generates a bigger result image than the shadow that has no blur, is there a way to generate the same
sized image with and without blur in the shadow?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: drop shadow or similar effects

Post by fmw42 »

that is because you did not specify an exact size and let IM compute the size. It needs 2 pixels more on the right and bottom due to the shaddow.

why does it matter? if you don't like it just use -crop or -shave to remove the added data (2 on the right and 2 at the bottom). see http://www.imagemagick.org/Usage/crop/#crop and http://www.imagemagick.org/Usage/crop/#shave
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

Re: drop shadow or similar effects

Post by javismiles »

thank you very much, Anthony just posted a great solution in another post using
composite to preserve the image size, works great

convert rose: -bordercolor None -border 10x10 \
\( +clone -background navy -shadow 80x3+5+5 \) \
-compose DstOver -composite -compose Over shadow_space.png

the post is : viewtopic.php?f=1&t=17709&p=66930#p66930

thank you for your help also

jav
Post Reply