Drop shadow on text

僤鯓⒐⒋嵵緔 提交于 2019-12-30 02:12:27

问题


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?


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/8289297/drop-shadow-on-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!