From: wojjie at gmail dot com
Operating system: All
PHP version: 5.2.3
PHP Bug Type: GD related
Bug description: ImageLine w/ antialias = 1px shorter
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.
--
Edit bug report at http://bugs.php.net/?id=42434&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=42434&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=42434&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=42434&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=42434&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=42434&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=42434&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=42434&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=42434&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=42434&r=support
Expected behavior: http://bugs.php.net/fix.php?id=42434&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=42434&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=42434&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=42434&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=42434&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=42434&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=42434&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=42434&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=42434&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=42434&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=42434&r=mysqlcfg