php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48349 imagecopyresampled() sprinkles photos with multi-colored pixels
Submitted: 2009-05-21 03:31 UTC Modified: 2009-12-31 01:00 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: droidix at gmail dot com Assigned: pajoye (profile)
Status: No Feedback Package: GD related
PHP Version: 5.2.9 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: droidix at gmail dot com
New email:
PHP Version: OS:

 

 [2009-05-21 03:31 UTC] 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




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-22 10:04 UTC] 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-12-23 12:58 UTC] pajoye@php.net
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?
 [2009-12-31 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 12 19:01:30 2024 UTC