透明叠加创建 PNG
Transparent Overlay Creating PNG
我有下面的功能,我已经把它调整到我需要的大小,现在我要添加背景图像,然后希望在所有叠加文本上只添加具有透明背景的文本叠加层,但是 imagefilledrectangle
应用变量 $white
这是预期的,我试图看看是否有告诉函数是透明的而不是接受颜色,在这种情况下是白色, PHP 文档说颜色是 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';
}
}
}
我尝试在 imagefilledrectangle
之前添加 imagecolortransparent($im, $white);
,但没有任何区别。
明白了,函数中不需要 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';
}
}
}
我有下面的功能,我已经把它调整到我需要的大小,现在我要添加背景图像,然后希望在所有叠加文本上只添加具有透明背景的文本叠加层,但是 imagefilledrectangle
应用变量 $white
这是预期的,我试图看看是否有告诉函数是透明的而不是接受颜色,在这种情况下是白色, PHP 文档说颜色是 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';
}
}
}
我尝试在 imagefilledrectangle
之前添加 imagecolortransparent($im, $white);
,但没有任何区别。
明白了,函数中不需要 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';
}
}
}