首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP GD文本边框在透明时显示不正确

PHP GD文本边框在透明时显示不正确
EN

Stack Overflow用户
提问于 2011-08-09 21:36:34
回答 1查看 1.5K关注 0票数 3

我已经看到了关于这个的其他问题,我已经尝试使用Alpha和imagetruecolortopalette来解决它,但没有骰子。我想做的是创建一个像text.php?test=somethinghere这样的页面,它会生成这样的图像:

http://davzy.com/screenshots/Sample_20String-20110809-101622.png

我希望背景是透明的,但正如你所看到的,那里仍然有一些红色:

代码语言:javascript
复制
<?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);
?>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-08-09 22:42:25

应将$red ImageColorAllocateAlpha的255值更改为0:

代码语言:javascript
复制
$red = ImageColorAllocateAlpha($im, 0, 0, 0, 127);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6997014

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档