Cphalcon: Phalcon\Image\Adapter\GD loses transparency on image resize

Created on 20 Jul 2016  路  10Comments  路  Source: phalcon/cphalcon

Issue: Phalcon's GD loses transparency of png file when it comes to resizing. Transparent part of image become black.

Phalcon information:

Version => 2.1.0r
Build Date => Jun  3 2016 14:01:39
Powered by Zephir => Version 0.9.2a-dev

Code to reproduce:

$image = new \Phalcon\Image\Adapter\GD($image_path);
$image->background('#fff', 0); // for test purposes, not necessary 
$image->resize(500, 500);
if ($image->save($images_dir . '/' . $model->id . '.png')) {
// ...
}
stale

Most helpful comment

@Jurigag @sergeyklay
image

All 10 comments

This is happening i think because imagealphablending(image, false); is not executed. Check here source - https://github.com/phalcon/cphalcon/blob/master/phalcon/image/adapter/gd.zep#L127 on php lower than 5.5.0 it's working correctly because there is _create method executed which set imagealphablending to false which preserve transparency.

That's right, feel free to PR. I don't feel too confident with Zephir

Well if you could check if it's true(like install php 5.4.x for instance) and check if it's working then someone could do it.

@sergeyklay also we could add some test on some small image, transparency can be detected by running through pixels checking their alpha. So some small image like 25x25 to check in tests if the transparency is kept after resize.

@Jurigag We can generate an empty image using the same adapter and then test on it. There is no need for including one in test assets. This way there is doesn't matter what the size of image is.

@Jurigag Just tested on PHP 5.4.45 and it works fine. As I said you were right

Is it fixed ? bug exists on php 5.5/5.6.

And every higher than 5.6

@Jurigag @sergeyklay
image

Thank you for contributing to this issue. As it has been 90 days since the last activity, we are automatically closing the issue. This is often because the request was already solved in some way and it just wasn't updated or it's no longer applicable. If that's not the case, please feel free to either reopen this issue or open a new one. We will be more than happy to look at it again! You can read more here: https://blog.phalconphp.com/post/github-closing-old-issues

I encountered the same issue:

$gd = new \Phalcon\Image\Adapter\Gd($tempFilePath);
$gd->resize($newWidth, $newHeight);
$gd->save($localPath, 90);

The resulting image has black background where it was transparent before.

Versions:

  • PHP 7.2.16-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Mar 7 2019 20:23:06) ( NTS )
  • Phalcon 3.4.3 Feb 25 2019 18:53:06
  • Zephir 0.10.14-975ad02db4
Was this page helpful?
0 / 5 - 0 ratings