我已经看到了关于此的其他问题,我尝试使用Alpha和imagetruecolortopalette来修复它,但没有骰子。我要做的是创建一个像text.php?test = somethinghere的页面,它会生成如下图像:
http://davzy.com/screenshots/Sample_20String-20110809-101622.png
我希望背景透明,但正如你所看到的还有一些红色:
<?php
// The text to draw width
$text = $_GET['t'];
$font = 'fontname.ttf';
$width = imagettfbbox(7, 0, $font, $text);
// Create the image
$im = imagecreatetruecolor($width[2] - $width[0] + 2, 11);
imagetruecolortopalette($im,false, 2);
imageSaveAlpha($im,true);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 108, 108, 108);
$red = ImageColorAllocateAlpha($im, 255, 0, 0, 127);
imagefill($im, 0, 0, $red);
//draw borders
imagettftext($im, 7, 0, 0, 8, $grey, $font, $text);
imagettftext($im, 7, 0, 2, 8, $grey, $font, $text);
imagettftext($im, 7, 0, 1, 7, $grey, $font, $text);
imagettftext($im, 7, 0, 1, 9, $grey, $font, $text);
//draw font
imagettftext($im, 7, 0, 0, 7, $grey, $font, $text);
imagettftext($im, 7, 0, 2, 7, $grey, $font, $text);
imagettftext($im, 7, 0, 0, 9, $grey, $font, $text);
imagettftext($im, 7, 0, 2, 9, $grey, $font, $text);
// Add the text
imagettftext($im, 7, 0, 1, 8, $white, $font, $text);
//show
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>
答案 0 :(得分:2)
应将$ red ImageColorAllocateAlpha的255值更改为0:
$red = ImageColorAllocateAlpha($im, 0, 0, 0, 127);