在文本上添加阴影

发布于 2024-12-18 02:07:20 字数 101 浏览 3 评论 0原文

我正在寻找使用 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.

Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一向肩并 2024-12-25 02:07:20

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

这是一个例子,我在一些文本上放置阴影,然后将其叠加在背景图像上......

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

希望这个有帮助,

罗杰

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

聽兲甴掵 2024-12-25 02:07:20

GD 无法立即做到这一点。如果可以的话,请使用 ImageMagick。有关如何制作形状阴影的示例此处

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文