ZFGC

Resources => Coding => Topic started by: AleX_XelA on October 31, 2006, 03:41:13 pm

Title: Help with GD library [PHP]
Post by: AleX_XelA on October 31, 2006, 03:41:13 pm
Hey there guys, lately I've been toying around with the GD library, and more precisely writting text on top of an image. As you may already know, there's a function that lets you use a .ttf font "ImageTTFText". The thing is, this function anti-aliases the text, and I don't want that to happen. Can anyone help me?
I'm not sure if it's the anti-aliasing that makes it so bad, but if I write the same thing in Paint, with the same size, it won't look the same.

(http://img288.imageshack.us/img288/6724/testfb8.png)

On the left side is the text generated by the PHP code, which calls the Verdana font, and sets the size to "7". On the right side, is the font created using MSPaint, Verdana, size "7".

How can I fix this so it looks like the Paint output?
Title: Re: Help with GD library [PHP]
Post by: Windy on October 31, 2006, 05:37:12 pm
try using a negative color index

Code: [Select]
$textColour = ImageColorAllocate($image, 255, 255, 255);
ImageTTFText($image, 8, 0, 0, 0, -$textColour, $font, $text);
Title: Re: Help with GD library [PHP]
Post by: AleX_XelA on October 31, 2006, 05:49:28 pm
It's better, but I still don't get the exact result I want, at least the anti-aliasing is gone, but the shape of the letters is not the same. I wonder how I could fix that?
Title: Re: Help with GD library [PHP]
Post by: AleX_XelA on October 31, 2006, 06:09:10 pm
Sol, I'm testing this locally, so that can't be the reason :S The more I think about this problem, the more I have a headache...

Edit : Oh if you have a complete other solution to this problem, like using another function or even another library, please tell!
Title: Re: Help with GD library [PHP]
Post by: Naz on November 04, 2006, 12:10:24 am
It might help us (Yes, very simple code, but still) if you post the code.  It could be that the background color or other elements are somehow effecting the way it looks.
Title: Re: Help with GD library [PHP]
Post by: AleX_XelA on November 04, 2006, 12:14:28 am
Sure thing, here you go :

Code: PHP
  1. <?php
  2. header ("Content-type: image/png");
  3. $image = imagecreatefrompng ("images/test.png");
  4. $txt_color = ImageColorAllocate ($image, 232, 232, 232);
  5. ImageTTFText ($image, 7, 0, 23, 17, -$txt_color, "/font/verdana.ttf", "Test");
  6. imagepng($image);
  7. ?>

test.png is just a square with the same color as the one shown in the first post.
Title: Re: Help with GD library [PHP]
Post by: Windy on November 04, 2006, 06:50:52 am
after testing that code, i just can't see what the problem is, when i do it, it almost looks exactly like the one in paint (except there's a 1 pixel difference between the 't' and 'est')

Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved