用php生成抗锯齿透明png图像

用php生成抗锯齿透明png图像,php,tags,transparency,antialiasing,Php,Tags,Transparency,Antialiasing,我读过很多关于生成透明图像的文章,但仍然存在透明度问题。首先,这里是我的代码: <?php $text = 'I feel dirty with those borders'; $color = array( 255, 128, 0); $font = 'arial.ttf'; $size = 44; // Create the image $testImg = imagecreatetruecolor(20, 20); $testCol = imagecolorallocate($te

我读过很多关于生成透明图像的文章,但仍然存在透明度问题。首先,这里是我的代码:

<?php
$text = 'I feel dirty with those borders';
$color = array( 255, 128, 0);
$font = 'arial.ttf';
$size = 44;

// Create the image
$testImg = imagecreatetruecolor(20, 20);
$testCol = imagecolorallocate($testImg, $color[0], $color[1], $color[2]);
$rect = imagettftext($testImg, $size, 0, 0, 0, $testCol, $font, $text);
$width = $rect[4] - $rect[0] + 2;
$height = $rect[1] - $rect[5];
$yOffset = -$rect[5];

imagedestroy($testImg);

$img = imagecreatetruecolor( $width, $height);
imageantialias ( $img, true);
$black = imagecolorallocate($img, 0, 0, 0);
imagecolortransparent($img, $black);
$col = imagecolorallocate($img, $color[0], $color[1], $color[2]);
$rect = imagettftext($img, $size, 0, -1, $yOffset, $col, $font, $text);
imagepng($img, "test.png");
imagedestroy($img);

?>
<html>
<body bgcolor="ffFFa0">
<img src="test.png" />
</body>
</html>

如果我用这个代码生成一个图像,文本周围会有黑色边框,字母的颜色不是完全不透明或完全透明的。我认为原因是只有100%黑色的像素是透明的。但还有什么别的办法呢?我还尝试使用AlphaBlinding,但没有成功

有谁能给我一个提示或者一个好例子的链接吗

提前谢谢


Paracus

我在stackoverflow搜索了一段时间后偶然找到了答案。因为我不知道如何链接到这个答案或评论另一个答案,所以我想在问题“使用PHP的GDlib imagecopyresampled时能否保持PNG图像的透明度?”(32243)Jorrit Schippers的注释为我提供了我在neath下描述的解决方案的轨迹。非常感谢$边框=imagecreatefrompng(“b.png”)$outX=120$outY=180$其他=imagecreatefromjpeg(“b.jpg”)$inX=100$inY=150$dst=ImageCreateTureColor($outX,$outY);imagealphablending($dst,false)$颜色=imagecolorallocatealpha($dst,0,0,0,127);图像填充($dst,0,0,$color);imagealphablending($dst,true);图像拷贝($dst,$tutor,($outX-$inX)/2,($outY-$inY)/2,0,0,$inX,$inY);imagecopy($dst、$border、0、0、0、$outX、$outY);imagesavealpha($dst,true);imagepng($dst,'out.png',9);