Quality decrease in libgd3 with upgrade to 2.1.1-4ubuntu0.16.04.5

Bug #1669734 reported by Ewald Stangl
14
This bug affects 3 people
Affects Status Importance Assigned to Milestone
libgd2 (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

Hello,

I use GD for resizing/branding images in PHP.
Everything worked fine with libgd3 <= 2.1.1-4build2

Since libgd3=2.1.1-4ubuntu0.16.04.5 there is a strange behavior when resizing transparent images with imagecopyresampled and putting them on a background.
A simple code example:

<?php
$outImage = imagecreatetruecolor(200, 200);

$color = imagecolorallocate($outImage, 233, 224, 218);
imagefilledrectangle($outImage, 0, 0, imagesx($outImage), imagesy($outImage), $color);

$im = imagecreatefrompng('https://www.expert24.com/200x.png');

imagecopyresampled($outImage, $im, 50, 25, 0, 0, imagesx($outImage) - 100, imagesy($outImage) - 50, imagesx($im), imagesy($im));

imagepng($im);
?>

With 2.1.1-4build2 everything looks fine but with newer versions there are stripes of a little darker color in the area of the transparent pixels of the overlayed image.

The version of php-gd or the php version itself (5.6, 7.0 from main or ondrej-ppa) doesn't have any influence.

The ubuntu changelog only says that there were some security fixes.

Is there a workaround?

regards
Ewald Stangl

Paul White (paulw2u)
affects: ubuntu → libgd2 (Ubuntu)
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in libgd2 (Ubuntu):
status: New → Confirmed
Revision history for this message
Roc (rocinwinter) wrote :

I had the same issue when using imagecopyresampled() to resize PNG images with transparent background. It introduced subtle noise to the transparent background in the resulting image. It looks like some kind of rounding issue within the resampling algorithm.

As a temporary workaround, reverting libgd back to 2.1.1-4build2 resolves the problem.

Revision history for this message
Ewald Stangl (ewaldst) wrote :

Since the last upgrade of the php7.0-gd package the workaround with the old version doesn't work perfectly anymore.

Using the new php7.0-gd with the old libgd3 creates bad borders on some images.
With the current libgd3 this behavior doesn't appear, but the strange background isn't fixed yet.

Revision history for this message
Pedro de Oliveira (falsovsky) wrote :

Hi, I've been digging for this bug for a few weeks now.

The first report of it is from ... 2008, in php.net: https://bugs.php.net/bug.php?id=45030

But it was fixed, because the same code on another distribution (in my case Gentoo) doesn't happen.

Can anyone look into this bug? This issue has been open since 2017 and it still exists on the latest version of PHP 7.4 on Ubuntu 20.

Revision history for this message
Pedro Francisco (pedrogfrancisco) wrote :

For reference, bug referred is
«Fixed bug #45030 (Destination image alpha channel noise when using imagecopyresampled). (Pierre)» from php-5.3.0beta1 release notes.

I was able to find a copy of the commit here https://repos.bgemi.net/sikofitt/php-src/-/commit/a3383ac3d7e21e54b1d7d89f308088d0692abc9f .

You'll have to compare the source and check if it is not fixed on Ubuntu's package, or if it is a new, unrelated bug.

Revision history for this message
Pedro de Oliveira (falsovsky) wrote :

That commit is for when PHP is built with the embedded libgd.
But in Ubuntu, PHP is using the system libgd instead of the one built in with PHP.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Related questions

Remote bug watches

Bug watches keep track of this bug in other bug trackers.