tags:

views:

251

answers:

1

I 'm trying to add text on a specific image. Its working perfectly but the quality of image is low especially for papyrus.ttf font. How can i improve the quality of text in the image. But i need high quality to print the output. Here is my code.. its very simple.

header("Content-Type: image/jpeg");
$im = imagecreatefromjpeg("cosmos.jpg");  
$black = ImageColorAllocate($im, 0, 0, 0);
Imagettftext($im, 14, 0, 10, 15, $black, 'papyrus.ttf', "Corey and Lisa ");
Imagettftext($im, 14, 0, 10, 35, $black, 'papyrus.ttf', " 1994, june");
Imagejpeg($im, '', 100);
ImageDestroy($im);

Download: http://wneeds.com/gdtest.zip

+4  A: 

If imageTTFText fails in Quality, the next step to try is ImageFTText(). It uses the FreeType library to render fonts, which usually means significantly better quality. It needs to be installed and compiled into PHP to work, which it most often is. Try calling the function and you'll see whether that is the case.

If that doesn't do, the next step is using ImageMagick either through the command line, or through the appropriate PHP extension. But try Freetype first, it could already be enough.

Pekka
Completely agree. If you don't care about resources you can try to make the image larger than needed and downsize to your needed size which should be slight quality improvement of the font, but it is a bit resource waste.
Ivo Sabev
thanks for all. I have tried with imagefttext(). But not getting better quality. i didn't use imagemagick before. So i think i have to go on that. but i was expecting more from gd. The code i supplied is a simple.. but in my system , i made for dynamic packets with dynamic message. so i have to change lot of thing if i go with image magic. @pekka can u pls check the code with imageFTText() and check the output. u may can find out whats happening. may be i'm doing some wrong. i will be grateful to u if u change the source and give me a simple solution. thanks again.
apueee
@apu can you post some images of real live examples please, along with images of what it is supposed to look like?
Pekka
in my question i have posted a zip file link.In that folder all files are available. http://wneeds.com/gdtest.zip.expected output is here. its generated with photoshop. http://wneeds.com/mike%20and%20kendra.jpg
apueee
@apueee I don't have a PHP with Freetype handy, and versions can differ. Can you make a screenshot of the result you're getting right now?
Pekka
http://imm.io/hjO
apueee
@apueee Hmm. That is smaller than the photoshop image you show, will that be the actual target size? That is already the result of a Freetype text, right? Can you use `phpinfo()` to find out which version of Freetype is installed (1 or 2)?
Pekka
freetype version is ok. http://imm.io/hl0
apueee
@apueee Hm. Youc ould try generating a considerably larger image (like, 4 times as large as you need it), writing into that and scaling it down using `imagecopyresampled` http://www.php.net/imagecopyresampled that *may* improve quality somewhat. If that doesn't help, I don't know any good way except ImageMagick I'm afraid.
Pekka
me also thinking for larger image. I'm trying to do that. thanks for ur patience and help...
apueee