php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #66887 imagescale - poor quality of scaled image
Submitted: 2014-03-12 08:23 UTC Modified: 2014-03-12 16:16 UTC
From: mruz at poczta dot onet dot pl Assigned: remi
Status: Closed Package: GD related
PHP Version: 5.5.10 OS: openSUSE 13.1
Private report: No CVE-ID:
 [2014-03-12 08:23 UTC] mruz at poczta dot onet dot pl
Description:
------------
Is it intended behavior that the quality of http://www.php.net/function.imagescale is much worse than http://www.php.net/function.imagecopyresampled ? 

I'm using PHP 5.5.9, but see in the PHP 5.5.10 changelog nothing on this issuse was changed.

Test script:
---------------
$oryginal = imagecreatefromjpeg('test.jpg');

$img = imagecreatetruecolor(300, 200);
imagecopyresized($img, $oryginal, 0, 0, 0, 0, 300, 200, 600, 400);
imagejpeg($img, 'test1.jpg', 90);
echo '<img src="test1.jpg" /><br />';

$img = imagescale($oryginal, 300, 200);
imagejpeg($img, 'test2.jpg', 90);
echo '<img src="test2.jpg" /><br />';



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-03-12 08:28 UTC] mruz at poczta dot onet dot pl
Or even http://www.php.net/function.imagecopyresized
 [2014-03-12 09:20 UTC] pajoye@php.net
-Status: Open +Status: Feedback
 [2014-03-12 09:20 UTC] pajoye@php.net
imagescale has many different algorithms, some are good for downscaling other for upscaling. Performance differs too from one to another.

Try other algorithms and use the right one depending on what you want to do. Also having an example image may help to answer. Can you post a link to one?
 [2014-03-12 10:02 UTC] mruz at poczta dot onet dot pl
I resized to 600x400:
http://mruz.pl/test/test1.jpg (imagecopyresized)
http://mruz.pl/test/test2.jpg (imagescale)
http://mruz.pl/test/test.jpg (oryginal)

If I apply white background after imagescale():
imagecolorallocatealpha($background, r, g, b, $opacity);
imagealphablending($background, true);
imagecopy($background, $img, 0, 0, 0, 0, $width, $height)

is much worse..
http://mruz.pl/test/test3.jpg (background after imagescale)
 [2014-03-12 10:20 UTC] pajoye@php.net
Please ignore the background call. It is totally unrelated to this problem. JPEG does not have alpha, so could you please using only the scale function and compare the results?

See http://www.php.net/imagesetinterpolation for the different algorithms available.
 [2014-03-12 10:37 UTC] mruz at poczta dot onet dot pl
$algs = [
IMG_BELL,
IMG_BESSEL,
IMG_BICUBIC,
IMG_BICUBIC_FIXED,
IMG_BILINEAR_FIXED,
IMG_BLACKMAN,
IMG_BOX,
IMG_BSPLINE,
IMG_CATMULLROM,
IMG_GAUSSIAN,
IMG_GENERALIZED_CUBIC,
IMG_HERMITE,
IMG_HAMMING,
IMG_HANNING,
IMG_MITCHELL,
IMG_POWER,
IMG_QUADRATIC,
IMG_SINC,
IMG_NEAREST_NEIGHBOUR,
IMG_WEIGHTED4,
IMG_TRIANGLE,
];

foreach ($algs as $key => $alg) {
    $img = imagescale($oryginal, 600, 400, $alg);
    imagejpeg($img, 'tmp'.$key.'.jpg', 90);
    echo '<img src="tmp'.$key.'.jpg" /><br />';
}

All images are the same...
 [2014-03-12 10:55 UTC] pajoye@php.net
and which result do you get? link pls
 [2014-03-12 11:02 UTC] mruz at poczta dot onet dot pl
Sorry, http://mruz.pl/test/tmp0.jpg , available file names: tmp[0-20].jpg
 [2014-03-12 11:12 UTC] pajoye@php.net
Looks like a bug.

Which gd do you use? Bundled or system? See phpinfo

I also need to know which architecture you use (cpu)
 [2014-03-12 11:18 UTC] mruz at poczta dot onet dot pl
Bundled, x86_64
 [2014-03-12 13:54 UTC] remi@php.net
Can you try with 
    imagesetinterpolation($oryginal, $alg);
    $img = imagescale($oryginal, 600, 400);

$alg option of imagescale is ignored (yes, this is a "goto fail;" bug)

It seems IMG_BILINEAR_FIXED produce this bad quality image.
IMG_BICUBIC_FIXED and IMG_NEAREST_NEIGHBOUR seems to work better.
 [2014-03-12 14:24 UTC] mruz at poczta dot onet dot pl
Yes, if I run imagesetinterpolation before imagescale it works fine.

In this case IMG_BILINEAR_FIXED and IMG_WEIGHTED4 not look nice, the rest of the algorithms is OK.
 [2014-03-12 14:31 UTC] remi@php.net
New bug #66893 open for ignored parameter.

Keeping this one for "poor quality" using default / IMG_BILINEAR_FIXED method.
 [2014-03-12 14:49 UTC] mruz at poczta dot onet dot pl
Thanks, I did update the tmp images, if anyone would like to see them:
http://mruz.pl/test/tmp4.jpg (IMG_BILINEAR_FIXED)
 [2014-03-12 16:16 UTC] remi@php.net
-Assigned To: +Assigned To: remi
 [2014-03-12 16:16 UTC] remi@php.net
-Status: Feedback +Status: Closed
 
PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Fri Sep 04 10:01:36 2015 UTC