Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Help with GD library [PHP]  (Read 1692 times)

0 Members and 1 Guest are viewing this topic.
Help with GD library [PHP]
« on: October 31, 2006, 03:41:13 pm »
  • Credits to BaB
  • *
  • Reputation: +2/-0
  • Offline Offline
  • Posts: 807
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.



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?
Logged
Re: Help with GD library [PHP]
« Reply #1 on: October 31, 2006, 05:37:12 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 2245
try using a negative color index

Code: [Select]
$textColour = ImageColorAllocate($image, 255, 255, 255);
ImageTTFText($image, 8, 0, 0, 0, -$textColour, $font, $text);
« Last Edit: October 31, 2006, 05:44:28 pm by Windy »
Logged
Re: Help with GD library [PHP]
« Reply #2 on: October 31, 2006, 05:49:28 pm »
  • Credits to BaB
  • *
  • Reputation: +2/-0
  • Offline Offline
  • Posts: 807
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?
Logged
Re: Help with GD library [PHP]
« Reply #3 on: October 31, 2006, 06:09:10 pm »
  • Credits to BaB
  • *
  • Reputation: +2/-0
  • Offline Offline
  • Posts: 807
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!
« Last Edit: October 31, 2006, 06:12:00 pm by AleX_XelA »
Logged

Naz

Re: Help with GD library [PHP]
« Reply #4 on: November 04, 2006, 12:10:24 am »
  • Ph34r the toast.
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 374
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.
Logged
Don't read this.
Re: Help with GD library [PHP]
« Reply #5 on: November 04, 2006, 12:14:28 am »
  • Credits to BaB
  • *
  • Reputation: +2/-0
  • Offline Offline
  • Posts: 807
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.
Logged
Re: Help with GD library [PHP]
« Reply #6 on: November 04, 2006, 06:50:52 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 2245
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')
Logged
Pages: [1]   Go Up

 


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



Page created in 0.262 seconds with 53 queries.