首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在右下角的换行图片中添加图片水印?

如何在右下角的换行图片中添加图片水印?
EN

Stack Overflow用户
提问于 2016-09-18 15:45:06
回答 1查看 313关注 0票数 2

下面是生成文本换行图像的代码。如何在右下角的换行图片中添加图片水印?谢谢。

代码语言:javascript
复制
private function warpTextImage($text)
{
    $font = $this->font;
    $text_dimensions = imagettfbbox(30, 0, $font, $text);
    $text_width = abs($text_dimensions[4] - $text_dimensions[0]);
    $text_height = abs($text_dimensions[5] - $text_dimensions[1]);
    $img_width = abs($text_dimensions[4] - $text_dimensions[0]) + 40;
    $img_height = abs($text_dimensions[5] - $text_dimensions[1]) + 40;
    $image = imagecreate($img_width, $img_height);
    $background = imagecolorallocate($image, $this->background_color[0], $this->background_color[1], $this->background_color[2]);
    $color = imagecolorallocate($image, $this->text_color[0], $this->text_color[1], $this->text_color[2]);
    $x = ($img_width - $text_width) / 2 - 4;
    $y = ($img_height - $text_height) / 2 + 30;
    imagettftext($image, 30, 0, $x, $y, $color, $font, $text);
    return $image;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-18 15:49:18

您可以使用Intervention packageinsert()方法来实现:

代码语言:javascript
复制
$img->insert('public/watermark.png', 'bottom-right', 10, 10);
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39555279

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档