Page 1 of 1

drop shadow or similar effects

Posted: 2010-12-19T10:49:11-07:00
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 :)

Re: drop shadow or similar effects

Posted: 2010-12-19T11:01:52-07:00
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

Re: drop shadow or similar effects

Posted: 2010-12-19T12:37:19-07:00
by fmw42
Yes, see hard and soft shadow examples at http://www.imagemagick.org/Usage/fonts

Re: drop shadow or similar effects

Posted: 2010-12-19T14:46:16-07:00
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

Re: drop shadow or similar effects

Posted: 2010-12-19T14:54:09-07:00
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?

Re: drop shadow or similar effects

Posted: 2010-12-19T15:02:49-07:00
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

Re: drop shadow or similar effects

Posted: 2010-12-19T15:24:58-07:00
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.

Re: drop shadow or similar effects

Posted: 2010-12-19T15:31:47-07:00
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

Re: drop shadow or similar effects

Posted: 2010-12-19T15:33:48-07:00
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

Re: drop shadow or similar effects

Posted: 2010-12-19T16:09:54-07:00
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

Re: drop shadow or similar effects

Posted: 2010-12-19T16:31:20-07:00
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?

Re: drop shadow or similar effects

Posted: 2010-12-19T16:53:18-07:00
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

Re: drop shadow or similar effects

Posted: 2010-12-20T01:17:37-07:00
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