gpt4 book ai didi

php - 如何用 PHP 在图片上写不透明的文本?

转载 作者:行者123 更新时间:2023-12-05 04:55:48 24 4
gpt4 key购买 nike

我正在图片上写文字。到目前为止一切都很好,但我必须降低此文本的透明度或不透明度值。我对不透明度值尝试了以下方法,但我无法得到任何结果。

imagecolortransparent($image, imagecolorallocate($image, 0,0,0));



header('Content-type: image/jpeg');
$size = 50;
$degrees = 0;
$rl = 200;
$xy = 120;
$font = 'arial.ttf';
$text = "Watermark Text";
$image = imagecreatefromjpeg('image.jpg');
$textcolor = imagecolorallocate($image, 230, 230, 230);
imagettftext($image, $size, $degrees ,$rl, $xy, $textcolor, $font, $text);
imagejpeg($image);
imagedestroy($image);

实际结果:https://prnt.sc/vy8axf

预期结果:https://prnt.sc/vy8cnz

最佳答案

你可以使用 imagecolorallocatealpha()将 alpha channel 分配给 $textcolor :

$textcolor = imagecolorallocatealpha($image, 230, 230, 230, 100);

例如:

$size = 50;
$degrees = 0;
$rl = 200;
$xy = 120;
$font = 'arial.ttf';
$text = "Watermark Text";

$image = imagecreatefromjpeg('image.jpg');
$textcolor = imagecolorallocatealpha($image, 230, 230, 230, 100);
imagettftext($image, $size, $degrees ,$rl, $xy, $textcolor, $font, $text);

header('Content-type: image/jpeg');
imagejpeg($image);
imagedestroy($image);

请注意:

A value between 0 and 127.0 indicates completely opaque while 127 indicates completely transparent.

关于php - 如何用 PHP 在图片上写不透明的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65199177/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com