note 19222 added to function.imagettftext
| From: | mshambaugh#nucleusinc dot com at php2 dot chek dot com | Date: | Wed, 20 Feb 2002 07:02:41 +0000 |
| Subject: | note 19222 added to function.imagettftext | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-26830@lists.php.net to get a copy of this message | ||
Here's a hack to overcome the poor quality of the text rendered by this function on truecolor
images:
1) Create a temporary palette image (with ImageCreate rather than ImageCreateTrueColor)
2) Render your text into that image
3) Use ImageJPEG to write it to disk
4) Use ImageCreateFromJPEG to load that file back - presto, your text is now truecolor and still
looks great
5) Set a transparency color if need be and composite your text image onto your original truecolor
image
Like so:
// Create paletted image...
$buff = imagecreate($imagewidth, $imageheight);
$background_color = ImageColorAllocate($buff, 255, 255, 255);
$color = ImageColorAllocate($buff, 0, 0, 0);
// Render clean text into it...
ImageTTFText($buff, $fontsize, 0, $pos_x, $pos_y, $color, $font, $string);
// Write it out as a JPEG...
$filename = "/tmp/test_".date("U").".jpg";
ImageJPEG($buff, $filename, 100);
ImageDestroy($buff);
// Pull it back in from the JPEG...
$buff = ImageCreateFromJPEG($filename);
// Composite it onto the original image...
$background_color = ImageColorAllocate($buff, 255, 255, 255);
imagecolortransparent($buff, $background_color);
ImageAlphaBlending($image, true);
ImageCopy($image, $buff, 0, 0, 0, 0, ImageSX($image), ImageSY($image));
ImageAlphaBlending($image, false);
ImageDestroy($buff);
--
http://www.php.net/manual/en/function.imagettftext.php
http://master.php.net/manage/user-notes.php?action=edit+19222
http://master.php.net/manage/user-notes.php?action=delete+19222
http://master.php.net/manage/user-notes.php?action=reject+19222