我已经看到了关于这个的其他问题,我已经尝试使用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);
?>发布于 2011-08-09 22:42:25
应将$red ImageColorAllocateAlpha的255值更改为0:
$red = ImageColorAllocateAlpha($im, 0, 0, 0, 127);https://stackoverflow.com/questions/6997014
复制相似问题