[英]Transparent Overlay Creating PNG
我具有以下功能,并且已经达到所需的大小,现在我要添加背景图像,然后希望在所有覆盖文本上仅添加具有透明背景的文本覆盖,但是imagefilledrectangle
应用变量$white
可以预期,我正在尝试查看是否有某种方法告诉该函数透明而不是接受一种颜色,在这种情况下为白色,PHP文档说该颜色是imagefilledrectangle
的必需参数,任何建议都imagefilledrectangle
赞赏。
背景图像是本地图像:
define("BACKGROUND_FILE", "background.png");
功能:
public function generateImage()
{
if (file_exists(BACKGROUND_FILE)) {
$im = @imagecreatefrompng(BACKGROUND_FILE);
if($im) {
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 115, 150, 195);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
$text = 'Test';
$font = 'arial_narrow_7.ttf';
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
imagepng($im);
imagedestroy($im);
} else {
echo 'Error';
}
}
}
我尝试添加imagecolortransparent($im, $white);
在imagefilledrectangle
之前,但没有任何区别。
弄清楚了,函数中不需要有imagefilledrectangle
线,下面给出了透明的覆盖文本元素,因为现在不应用填充。
public function generateImage()
{
if (file_exists(BACKGROUND_FILE)) {
$im = @imagecreatefrompng(BACKGROUND_FILE);
if($im) {
$black = imagecolorallocate($im, 115, 150, 195);
$text = 'Test';
$font = 'arial_narrow_7.ttf';
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
imagepng($im);
imagedestroy($im);
} else {
echo 'Error';
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.