#48349 [Fbk]: imagecopyresampled() sprinkles photos with multi-colored pixels
| From: | pajoye@php.net | Date: | Wed, 23 Dec 2009 12:58:58 +0000 |
| Subject: | #48349 [Fbk]: imagecopyresampled() sprinkles photos with multi-colored pixels | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-146059@lists.php.net to get a copy of this message | ||
ID: 48349
Updated by: pajoye@php.net
Reported By: droidix at gmail dot com
Status: Feedback
Bug Type: GD related
Operating System: Linux
PHP Version: 5.2.9
New Comment:
Don't try a snapshot as nothing changed in this code recently.
However the links to the images do not work, can you post new links
please?
Previous Comments:
------------------------------------------------------------------------
[2009-12-22 10:04:29] jani@php.net
Please try using this snapshot:
http://snaps.php.net/php5.2-latest.tar.gz
For Windows:
http://windows.php.net/snapshots/
------------------------------------------------------------------------
[2009-05-21 03:31:45] droidix at gmail dot com
Description:
------------
When using imagecopyresampled on a CentOS 5.3 and PHP 5.2.9 (also
tried the 5.3 snapshot) multi-colored pixels are sprinkled onto the
image. Running the same function in a loop produces a different image
every time using the same input.
I could not reproduce the issue on another CentOS 5.3 machine so I
think it could be related to the floating point unit on the box. Here
is the cpuinfo:
processor : 0
vendor_id : AuthenticAMD
cpu family : 6
model : 8
model name : AMD Athlon(tm) XP 2000+
stepping : 1
cpu MHz : 1662.500
cache size : 256 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 1
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca
cmov pat pse36 mmx fxsr sse syscall mmxext 3dnowext 3dnow up
nonstop_tsc ts
bogomips : 3326.67
To work around the issue for now, I changed the resample function in
the bundled gd library to use floats instead of doubles, and then used
the compiler flags -msse -mfpmath=sse to force the use of the SSE unit
instead of the built in FPU. This produced clean images!
In the GCC documentation, this model of CPU doesn't support doubles
for SSE instructions so that is why I changed them to floats.
Reproduce code:
---------------
<?php
$img = imagecreatefromjpeg("photo.jpg");
list($img_width, $img_height, $img_type, $img_attr) =
getimagesize("photo.jpg");
$new_width = 300;
$new_height = 400;
for ($i = 0; $i < 10; $i++) {
$nimg = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled ($nimg, $img, 0, 0, 1, 1, $new_width, $new_height,
$img_width - 2, $img_height - 2);
imagejpeg($nimg, "output$i.jpg", 80);
imagedestroy($nimg);
}
?>
Expected result:
----------------
Resized photos without noise. Here is the original photo used in the
resample:
http://bit.ly/yfS5w
Actual result:
--------------
Resized photo with noise, result is different each time. Here are
three
examples:
http://bit.ly/SOzNV
http://bit.ly/oXUsm
http://bit.ly/6gsCP
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48349&edit=1