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')) {
// ...
}
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

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:
Most helpful comment
@Jurigag @sergeyklay
