Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drop shadow on text

I am looking to add drop shadow to text on an image using PHP.

I am aware on how to add text to images and how some libraries allow you to add block shadowing, but I cannot see any which allow you to add a faded drop shadow.

Is this possible?

like image 776
user984580 Avatar asked Nov 27 '11 21:11

user984580


People also ask

How do you put a drop shadow on text?

In your Layers panel, click on the FX icon at the bottom of the panel. Then from the list of options, choose Drop Shadow, and you'll see different adjustments you can make. You can also choose Layer > Layer Style > Drop Shadow from the menu.

How do you shadow text on Iphone?

Select the text you want to change. In the Format sidebar, click the Style button near the top. If the text is in a table cell, click the Cell tab at the top of the sidebar instead of the Style button. In the Font section, click the Action pop-up menu , then select the Shadow checkbox.


2 Answers

What you want is Imagick::shadowImage ( float $opacity , float $sigma , int $x , int $y )

Here's an example where I put a drop shadow on some text and then superimpose that on a background image...

$background_layer = new Imagick('poster_pic_01.jpg'); # background image

$text_layer = new Imagick('transparent400.png'); # empty transparent png of the same size
$text_layer->annotateImage( $ImagickDraw, $pad_left, $pad_top, 0, "Your text here" );

/* create drop shadow on it's own layer */
$shadow_layer = $text_layer->clone(); 
$shadow_layer->setImageBackgroundColor( new ImagickPixel( 'black' ) ); 
$shadow_layer->shadowImage( 75, 5, 5, 5 ); 

/* composite original text_layer onto shadow_layer */
$shadow_layer->compositeImage( $text_layer, Imagick::COMPOSITE_OVER, 0, 0 ); 

/* composite shadow_layer (which now has text AND the shadow) onto image_layer */
$background_layer->compositeImage( $shadow_layer, Imagick::COMPOSITE_OVER, 0, 0 ); 

Hope this helps,

Roger

like image 183
Roger Heathcote Avatar answered Oct 05 '22 03:10

Roger Heathcote


GD can't do this out of the box. If you can, use ImageMagick. Examples on how to do shaped shadows here.

like image 42
Pekka Avatar answered Oct 05 '22 01:10

Pekka