php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55545 imagettftext() antialiasing depends on color allocation order
Submitted: 2011-08-31 03:27 UTC Modified: 2011-08-31 08:03 UTC
From: phpbugs at exaseb dot de Assigned:
Status: Not a bug Package: GD related
PHP Version: 5.3.8 OS: Windows XP, 32bit
Private report: No CVE-ID: None
 [2011-08-31 03:27 UTC] phpbugs at exaseb dot de
Description:
------------
GD version: bundled (2.0.34 compatible)

Using a negative $color parameter for imagettftext() does not produce antialiased text if the image is created with imagecreate() (as opposed to imagecreatetruecolor()) and the text color is the first color allocated.

I have not looked into this but I suppose the first color recieves an index of 0, thus a test for <0 always fails and antialiasing is never used. Using a negative color index is a really awful hack. imagettftext() should receive an additional parameter instead.


Test script:
---------------
<?php

$im = imagecreate(210, 50);
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 255, 255, 255);
imagefilledrectangle($im, 0, 0, 209, 49, $background_color);
imagettftext($im, 20, 0, 10, 20, -$text_color, "arial.ttf", "Antialiasing");
imagetruecolortopalette($im, FALSE, 255);
imagepng($im, "as_intended.png");
imagedestroy($im);

$im = imagecreate(210, 50);
$text_color = imagecolorallocate($im, 255, 255, 255);
$background_color = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 209, 49, $background_color);
imagettftext($im, 20, 0, 10, 20, -$text_color, "arial.ttf", "Antialiasing");
imagetruecolortopalette($im, FALSE, 255);
imagepng($im, "not_as_intended.png");
imagedestroy($im);

?> 

Expected result:
----------------
The script should produce two identical PNG images with not antialiased text.

Actual result:
--------------
The image as_intended.png shows the expected result whereas not_as_intended.png shows antialiased text where the text should not be antialiased.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-08-31 03:31 UTC] phpbugs at exaseb dot de
I compared this problem with #21554, #7769, #18455 and #15405 and think that it is slightly different so I opened a new issue.
 [2011-08-31 08:03 UTC] pajoye@php.net
-Status: Open +Status: Bogus
 [2011-08-31 08:03 UTC] pajoye@php.net
If you really want good antialiasing, use true color images.

Not sure why you call imagetruecolortopalette($im, FALSE, 255); anyway as you do 
have a palette image already (imagecreate creates palette images).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 07 11:01:31 2024 UTC