Page 1 of 1
Adding shadow on word wrapped text image
Posted: 2013-06-14T03:17:36-07:00
by busybee235
I want to add shadow to text on word wrapped text image. Googled many pages and experimented with gaussian, blur, shadow commands for dropping shadow but no success. I'm a newbie, recently started working with IM.
This is my code:
$line = "Anatidaephobia is the fear that somewhere in the world there is a duck watching you.";
exec("convert -size 500x -background white -pointsize 35 -font arial-italic -gravity center -fill black caption:\"$line\" output.jpg");
Thanks
Re: Adding shadow on word wrapped text image
Posted: 2013-06-14T03:57:48-07:00
by snibgo
See examples on
http://www.imagemagick.org/Usage/blur/#shadow
For your needs, you could do:
Code: Select all
convert ^
-size 500x -background None -pointsize 35 -font arial-italic -gravity center -fill black caption:%line% ^
( +clone -shadow 80x3+5+5 ) ^
+swap ^
-background White ^
-layers merge +repage ^
output.jpg
Windows script; adjust as required for your language.
Re: Adding shadow on word wrapped text image
Posted: 2013-06-14T07:40:34-07:00
by snibgo
Explanation of my script:
"-shadow" takes an image and replaces it with its shadow. The shadow of an opaque rectangular image will be a rectangle. We want shadows of the letters, not of the entire rectangle, so we write the letters on a transparent background ("-background None").
We need to put the "-shadow" within "( +clone ... )" because we want to keep the letters, not to replace them.
We want the letters to appear on top of the shadow (not the shadow on top of the letters), so we "+swap" before "-layers merge". We don't want any transparency in the final image, so we merge the layers with a white background. (Saving to jpg will automatically remove transparency, but by merging with a black background.)
We don't actually need "+repage", because this removes offsets that aren't stored in jpg files. If the output file was changed to be .png, we would have an offset in the file, which we probably would not want.
Re: Adding shadow on word wrapped text image
Posted: 2013-06-14T10:15:47-07:00
by busybee235
Thanks Snibgo, it worked.
Re: Adding shadow on word wrapped text image
Posted: 2013-06-16T04:11:12-07:00
by busybee235
Hey Snibgo, your code works absolutely fine on my localhost environment but doesn't work on my webhost. After checking I came to know that my hosting providers are providing IM version 5.5.6 Q16 which they installed in 2003. The shadow command doesn't work at all on their servers.
This doesn't works:
Code: Select all
exec("/usr/bin/convert -size 500x -background transparent -pointsize 30 -font verdana-bold -gravity center -fill white caption:\"$line\" ( +clone -shadow 100x2+3+0 ) +swap -background transparent -layers merge +repage output.png");
This works:
Code: Select all
exec("/usr/bin/convert -size 500x -background transparent -pointsize 30 -font verdana-bold -gravity center -fill white caption:\"$line\" output.png");
Even font verdana-bold not working. It is just plain old text image.
Can you provide any alternative to shadow command for shadow effect?
Thanks
Re: Adding shadow on word wrapped text image
Posted: 2013-06-16T04:49:42-07:00
by snibgo
I suggest you ask your hoster to upgrade IM.
You can list the available fonts with "convert -list font".
For shadows without using the "-shadow" command, see
http://www.imagemagick.org/Usage/blur/#shadow_internals
Re: Adding shadow on word wrapped text image
Posted: 2013-06-17T02:06:27-07:00
by busybee235
Thanks for replying snibgo, I talked to them, they told it will take a long time and will affect their clients. So, I can't say they will do it!
Can you tell me how can I add a layer of text of different color below like this:
to this code:
Code: Select all
exec("/usr/bin/convert -size 500x -background transparent -pointsize 30 -font verdana-bold -gravity center -fill white caption:\"$line\" output.png");
Thanks
Re: Adding shadow on word wrapped text image
Posted: 2013-06-17T05:23:13-07:00
by snibgo
Perhaps you can install IM in your user account, and use that. I don't use Unix, and can't advise.
For the "Anthony" example, something like this. I don't have the Candice font, so have used Arial. (Windows script; adjust for your language.)
Code: Select all
%IM%convert ^
-size 320x100 xc:lightblue -font Arial -pointsize 72 ^
-fill Black -draw "text 28,68 'Anthony'" ^
-fill White -draw "text 25,65 'Anthony'" ^
text_draw.png
Re: Adding shadow on word wrapped text image
Posted: 2013-06-18T10:19:01-07:00
by busybee235
I have a shared hosting so its impossible to for IM updation.
The code above you provided works with draw command, I want to make it work with below one. I tried many times but couldn't can you please help?
Code: Select all
exec("/usr/bin/convert -size 500x -background transparent -pointsize 30 -font verdana-bold -gravity center -fill white caption:\"$line\" output.png");
Adding a black layer of text and then the above one.
Thanks
Re: Adding shadow on word wrapped text image
Posted: 2013-06-18T10:57:19-07:00
by snibgo
Windows script:
Code: Select all
set line="Anatidaephobia is the fear that somewhere in the world there is a duck watching you."
%IM%convert ^
-size 500x -background None ^
-pointsize 35 -font arial-italic -gravity center ^
-fill Black caption:%line% -repage +2+2 ^
-fill White caption:%line% ^
-background LightBlue ^
-layers merge ^
out.png