在文本上投下阴影 [英] Drop shadow on text

查看:132
本文介绍了在文本上投下阴影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望使用PHP为图像上的文本添加阴影。

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.

这可能吗?

推荐答案

你想要的是Imagick :: shadowImage(float $ opacity,float $ sigma,int $ x,int $ y)

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 ); 

希望这会有所帮助,

Roger

这篇关于在文本上投下阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆