Границы текста PHP GD отображаются неправильно с прозрачностью - PullRequest
3 голосов
/ 09 августа 2011

Я видел другие вопросы по этому поводу, и я пытался использовать Alpha и imagetruecolortopalette, чтобы исправить это, но без игры в кости.Я пытаюсь сделать страницу наподобие text.php? Test = что-то здесь, и она создаст изображение, подобное этому:

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

1 Ответ

2 голосов
/ 09 августа 2011

Следует изменить значение 255 для $ red ImageColorAllocateAlpha на 0:

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