2011-08-09 60 views
3

我已经看到关于此问题的其他问题,我试过使用Alpha和imagetruecolortopalette来修复它,但没有骰子。我想要做的就是像text.php测试= somethinghere一个网页,它会产生这样的图像:PHP GD文本边框显示与透明度不正确

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); 
?> 

回答

2

应该在$红ImageColorAllocateAlpha的255值更改为0:

$red = ImageColorAllocateAlpha($im, 0, 0, 0, 127); 
+0

现在,它做同样的事情只能用黑色 –

+0

黑色的字体大纲是可取的,只是不是在词的开头的小额外的黑色右?尝试制作ImageColorAllocateAlpha RGB白色:$ red = ImageColorAllocateAlpha($ im,255,255,255,127); – tatorface

+0

现在它只用白色做同样的事情 –