Image intervention adding black noise to the background when saving a PNG as JPG
Asked Answered
B

0

6

I'm currently using intervention/image to resize images and save them as JPG.

I have the same code running locally in Windows and remotely in Ubuntu 20.20.

In Windows it does the conversion PNG to JPG converting the transparent background into white. However, in Ubuntu, is adding black noise on top of the white background.

The code I run is:

$resize = Image::make($img)->encode('jpg');
$resize->height() > $resize->width() ? $width = null : $height = null;
$resize->resize($width, $height, function ($constraint) {
    $constraint->aspectRatio();
});

Should I add something else before the encode in order to ensure that the transparency makes white?

enter image description here

Bakemeier answered 17/7, 2020 at 10:28 Comment(9)
On macOS I get white background using your code i.imgur.com/HcZwN3Q.jpg , by black noise...do you mean the black borders around the objects?Cannelloni
Thanks @SalimDjerbouh, I mean this i.imgur.com/W3AfS27.pngBakemeier
@InigoEC What image library are you using?Abyssal
Currently intervention/image support both gd and imagick.Abyssal
Try installing these optimization tools sudo apt install jpegoptim optipng pngquant gifsicle -y && npm install -g svgoCannelloni
@Abyssal I tried both, but none of them workBakemeier
@SalimDjerbouh do I need to update any configuration to make them work?Bakemeier
I have the same problem with ubuntu 20... did you solve?Mattock
I gave up and started saving it as PNG - I then display it in a white background anywayBakemeier

© 2022 - 2024 — McMap. All rights reserved.