php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42434 ImageLine w/ antialias = 1px shorter
Submitted: 2007-08-27 04:50 UTC Modified: 2009-07-28 20:35 UTC
Votes:11
Avg. Score:4.5 ± 0.9
Reproduced:10 of 10 (100.0%)
Same Version:2 (20.0%)
Same OS:4 (40.0%)
From: wojjie at gmail dot com Assigned: pajoye (profile)
Status: Closed Package: GD related
PHP Version: 5.2.6 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: wojjie at gmail dot com
New email:
PHP Version: OS:

 

 [2007-08-27 04:50 UTC] wojjie at gmail dot com
Description:
------------
This bug looks fixed in the GD library, but for some reason the GD included in PHP still has this.

What happens is when drawing a line with anti aliasing enabled, the resulting line is 1 pixel shorter than it should be.

Fix (using snapshot: php5.2-200708270430.tar.gz):
--- gd.c       2007-08-26 23:44:04.000000000 -0500
+++ gd.c        2007-08-26 23:44:28.000000000 -0500
@@ -1351,7 +1351,7 @@
                x = x1 << 16;
                y = y1 << 16;
                inc = (dy * 65536) / dx;
-               while ((x >> 16) < x2) {
+               while ((x >> 16) <= x2) {
                        gdImageSetAAPixelColor(im, x >> 16, y >> 16, col, (y >> 8) & 0xFF);
                        if ((y >> 16) + 1 < im->sy) {
                                gdImageSetAAPixelColor(im, x >> 16, (y >> 16) + 1,col, (~y >> 8) & 0xFF);
@@ -1373,7 +1373,7 @@
                x = x1 << 16;
                y = y1 << 16;
                inc = (dx * 65536) / dy;
-               while ((y>>16) < y2) {
+               while ((y>>16) <= y2) {
                        gdImageSetAAPixelColor(im, x >> 16, y >> 16, col, (x >> 8) & 0xFF);
                        if ((x >> 16) + 1 < im->sx) {
                                gdImageSetAAPixelColor(im, (x >> 16) + 1, (y >> 16),col, (~x >> 8) & 0xFF);


Reproduce code:
---------------
<?php
$im=imagecreatetruecolor(30,30);

$c1=ImageColorAllocate($im,255,255,255);
$c2=ImageColorAllocate($im,  0,  0,  0);
imagefill( $im,0,0, $c1 );

imageline($im,5,5, 25,5, $c2);
imageantialias($im,true);
imageline($im,5,25, 25,25, $c2);

header("Content-type: image/png");
imagepng($im);
imagedestroy($im);

?>


Expected result:
----------------
Two lines of equal length

Actual result:
--------------
Top line is longer than bottom line by 1 pixel.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-27 11:04 UTC] jani@php.net
Assigned to the maintainer.
 [2008-09-05 02:19 UTC] abc at abc dot abc
reproduced on PHP 5.2.6 / windows. problem is still there
 [2009-07-28 20:35 UTC] svn@php.net
Automatic comment from SVN on behalf of kalle
Revision: http://svn.php.net/viewvc/?view=revision&revision=286466
Log: Fixed bug #42434 (ImageLine w/ antialias = 1px shorter)
 - patch by wojjie at gmail dot com
 [2009-07-28 20:35 UTC] kalle@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2009-07-30 03:54 UTC] svn@php.net
Automatic comment from SVN on behalf of kalle
Revision: http://svn.php.net/viewvc/?view=revision&revision=286540
Log: Test case for bug #42434
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 27 16:01:27 2024 UTC