Skip to content

Nette\Utils\Image::resize alpha broken (black background) #202

Closed
@josefsabl

Description

@josefsabl

Version:

GD Support enabled
GD Version bundled (2.1.0 compatible)
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.9.1
GIF Read Support enabled
GIF Create Support enabled
JPEG Support enabled
libJPEG Version 9 compatible
PNG Support enabled
libPNG Version 1.6.34
WBMP Support enabled
XPM Support enabled
libXpm Version 30512
XBM Support enabled
WebP Support enabled

But the same bug can be observed on a production machine with Ubuntu Linux:

GD Support enabled
GD headers Version 2.2.5
GD library Version 2.2.5
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.8.1
GIF Read Support enabled
GIF Create Support enabled
JPEG Support enabled
libJPEG Version 8
PNG Support enabled
libPNG Version 1.6.34
WBMP Support enabled
XPM Support enabled
libXpm Version 30411
XBM Support enabled
WebP Support enabled

Bug Description

This (czech language) looks to be an evergreen. I am able to reproduce it with the latest version of package with the EXACT flag and PNG type. However I am positive that I also saw this with WEBP (as I originally had the problem with WEBP and switched to PNG to fix it, it actually helped ! For some time though and now it appeared again!? WTF.)

Steps To Reproduce

\Nette\Utils\Image::fromFile(__DIR__ . '/input.png')
    ->resize(100, 100, \Nette\Utils\Image::EXACT)
    ->save(__DIR__ . '/output.png', null, \Nette\Utils\Image::PNG);

input - but also "not works" with other images so I guess it is not the problem with the file.

output

Expected Behavior

Image with transparency preserved.

Possible Solution

I traced the problem down to this line $this->image = imagecrop($this->image, $r);. Commenting it out fixes the alpha problem, but the image is not cropped, obviously :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions