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?
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.
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.
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
GD can't do this out of the box. If you can, use ImageMagick. Examples on how to do shaped shadows here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With