php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70441 interpolation modes broken in imagescale
Submitted: 2015-09-06 18:35 UTC Modified: 2016-10-14 23:02 UTC
Votes:3
Avg. Score:4.0 ± 0.8
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: programmer at bardware dot de Assigned: pajoye (profile)
Status: Closed Package: GD related
PHP Version: 7.0.0RC2 OS: Windows 7
Private report: No CVE-ID: None
 [2015-09-06 18:35 UTC] programmer at bardware dot de
Description:
------------
I use the thread safe Version php-7.0.0RC2-Win32-VC14-x86.zip as provided on http://windows.php.net/qa/
I have a script to resize images. I use it with PHP 5.6 and everything's fine. The images are broken (look bad) when the same script is used in PHP 7.
I found out that when I use another $mode in the call to imagescale(...) the images are correct.
I looped over all modes and it seems BICUBIX_FIXED, BILINEAR_FIXED and NEAREST_NEIGHBOUR are the only ones producing good images.
I had been using CATMULLROM before.

Test script:
---------------
<?php
$arrInterpolMethod= [
	"IMG_BELL" => IMG_BELL
	, "IMG_BESSEL" => IMG_BESSEL
	, "IMG_BICUBIC" => IMG_BICUBIC
	, "IMG_BICUBIC_FIXED" => IMG_BICUBIC_FIXED
	, "IMG_BILINEAR_FIXED" => IMG_BILINEAR_FIXED
	, "IMG_BLACKMAN" => IMG_BLACKMAN
	, "IMG_BOX" => IMG_BOX
	, "IMG_BSPLINE" => IMG_BSPLINE
	, "IMG_CATMULLROM" => IMG_CATMULLROM
	, "IMG_GAUSSIAN" => IMG_GAUSSIAN
	, "IMG_GENERALIZED_CUBIC" => IMG_GENERALIZED_CUBIC
	, "IMG_HERMITE" => IMG_HERMITE
	, "IMG_HAMMING" => IMG_HAMMING
	, "IMG_HANNING" => IMG_HANNING
	, "IMG_MITCHELL" => IMG_MITCHELL
	, "IMG_POWER" => IMG_POWER
	, "IMG_QUADRATIC" => IMG_QUADRATIC
	, "IMG_SINC" => IMG_SINC
	, "IMG_NEAREST_NEIGHBOUR" => IMG_NEAREST_NEIGHBOUR
	, "IMG_WEIGHTED4" => IMG_WEIGHTED4
	, "IMG_TRIANGLE" => IMG_TRIANGLE
];

if( $im = imagecreatefromjpeg( 'D:/Daten/Lumia_820/WP_20150829_028.jpg' ) ) {

	$MaxWert = 2048;
	$Width = ImagesX($im);
	$Height = ImagesY($im);

	if($Width>$Height) {
		$NeuWidth = $MaxWert;
		$NeuHeight = round( ( $Height * ($NeuWidth / $Width) ) / 4 ) * 4;
	} else {
		$NeuHeight = $MaxWert;
		$NeuWidth = round( ( $Width * ($NeuHeight / $Height) ) / 4 ) * 4;
	}

	foreach( $arrInterpolMethod as $interpolName => $interpolConstant ) {
		$NeuImg = imagescale( $im, $NeuWidth, $NeuHeight, $interpolConstant );
		ImageInterlace( $NeuImg, 1 );
		ImageJPEG($NeuImg, 'D:/Daten/php/WP_20150829_028_'.$interpolName.'.jpg', 80);
		ImageDestroy($NeuImg);
	}

	ImageDestroy($im);
}


Expected result:
----------------
I expect to get 20 not broken looking images


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-09-06 23:14 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2015-09-06 23:14 UTC] cmb@php.net
I can confirm this issue. The following script is supposed to
produce a plain red image:

    <?php
    $w1 = 1024; $h1 = 768;
    $w2 = 640; $h2 = 480;
    $img = imagecreatetruecolor($w1, $h1);
    $red = imagecolorallocate($img, 255, 0, 0);
    imagefilledrectangle($img, 0, 0, $w1, $h1, $red);
    $scaledImage = imagescale($img, $w2, $h2, IMG_CATMULLROM);
    imagepng($scaledImage, '70441.png');
    ?>

However, with PHP 7 on Windows (x86 and x64) it produces a checked
pattern. Linux builds don't seem to be affected. I've tested with
the bundled libgd only.
 [2016-06-07 15:21 UTC] pajoye@php.net
Can you reproduce it with master, or 5.x? I cannot repro it on Windows (and linux  too as you said).
 [2016-06-07 15:21 UTC] pajoye@php.net
-Status: Verified +Status: Feedback -Assigned To: +Assigned To: pajoye
 [2016-06-07 21:10 UTC] programmer at bardware dot de
-Status: Feedback +Status: Assigned
 [2016-06-07 21:10 UTC] programmer at bardware dot de
I cannot reproduce it with PHP 7.0.7-nts-Win32-VC14-x64. I had reproduced it with PHP 7.0.6 before.
 [2016-06-08 01:24 UTC] pajoye@php.net
-Status: Assigned +Status: Closed
 [2016-06-08 01:24 UTC] pajoye@php.net
The fix for this bug has been committed.

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/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2016-10-14 23:02 UTC] programmer at bardware dot de
Finally realize it was fixed by https://bugs.php.net/bug.php?id=72227
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 21:01:29 2024 UTC