Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
GD Library and anti-aliasing
Old 02-08-2009, 03:35 AM GD Library and anti-aliasing
Novice Talker

Posts: 5
Trades: 0
I've searched and searched and I cannot find an answer to this...

I'm trying to make an image using GD that has a transparent background and anti-aliased text in it. Unfortunately, this seems completely impossible but I'm sure I'm totally missing something.

I'm new to GD, so I hope I'm just missing something really simple.

Here's examples:
http://www.xbg4y.com/test.html

The top one is imagefill white with black text.
The bottom one is imagefill white, imagecolortransparent white, and then black text.

In an attempt to anti-alias, it does it as if it were still on the white background instead of anti-aliasing into transparency. I know you can turn off anti-aliasing, but then there would be no point in using GD to begin with...

Any ideas...? Is there something fancy you can do with alpha channels?
mradun is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-08-2009, 05:09 AM Re: GD Library and anti-aliasing
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
PHP Code:
<?php
header
('content-type: image/png');
$im imagecreatetruecolor(800,600);

// Important stuff
// Allocate a transparent background color
$bg imagecolorallocatealpha($im,255,0,0,127);
// ..and a non-transparent text color
$text imagecolorallocate($im,0,0,0);
// Turn on full alpha channel saving for PNG images
imagesavealpha($im,true);

// Fill with transparent and text with the other
imagefill($im,0,0,$bg);
imagettftext($im,40,0,50,50,$text,'C:\Windows\Fonts\arial.ttf','S58G');

imagepng($im);
?>
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Old 02-08-2009, 10:01 PM Re: GD Library and anti-aliasing
Novice Talker

Posts: 5
Trades: 0
Thanks a lot, that works perfectly.
mradun is offline
Reply With Quote
View Public Profile
 
Old 09-30-2009, 06:59 AM Re: GD Library and anti-aliasing
Junior Talker

Posts: 1
Name: Sujith Kumar.G.John
Trades: 0
really good code but i have try to avoid the distortion in text ,esp in outer side of each text ,for example the letter "U" the curved portion look like
Pixelation ,do you have any idea to avoid the same ,if so please let me know
thank you
image link :http://suzerain.isgreat.org/pixlise.JPG
please cut and copy the url don't click
Best regards,
Sujith






Quote:
Originally Posted by Insensus View Post
PHP Code:
<?php
header
('content-type: image/png');
$im imagecreatetruecolor(800,600);

// Important stuff
// Allocate a transparent background color
$bg imagecolorallocatealpha($im,255,0,0,127);
// ..and a non-transparent text color
$text imagecolorallocate($im,0,0,0);
// Turn on full alpha channel saving for PNG images
imagesavealpha($im,true);

// Fill with transparent and text with the other
imagefill($im,0,0,$bg);
imagettftext($im,40,0,50,50,$text,'C:\Windows\Fonts\arial.ttf','S58G');

imagepng($im);
?>

Last edited by johnsujith; 09-30-2009 at 07:06 AM..
johnsujith is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to GD Library and anti-aliasing
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.49428 seconds with 12 queries