gpt4 book ai didi

laravel - 将PNG另存为JPG时,图像干预会在背景上添加黑噪声

转载 作者:行者123 更新时间:2023-12-03 15:02:58 24 4
gpt4 key购买 nike

我目前正在使用intervention/image调整图像大小并将其另存为JPG。
我在Windows中本地运行,在Ubuntu 20.20中远程运行相同的代码。
在Windows中,它将PNG转换为JPG,将透明背景转换为白色。但是,在Ubuntu中,在白色背景之上添加了黑色噪音。
我运行的代码是:

$resize = Image::make($img)->encode('jpg');
$resize->height() > $resize->width() ? $width = null : $height = null;
$resize->resize($width, $height, function ($constraint) {
$constraint->aspectRatio();
});
我是否应该在 encode之前添加其他内容,以确保透明度变为白色?
enter image description here

最佳答案

来自:image.intervention.io/getting_started/configuration

Memory Settings
Image manipulation in PHP is a very memory consuming task. Since most tasks in PHP don't exhaust default memory limits, you have to make sure your PHP configuration is able to allocate enough memory to handle large images.
The following php.ini directives are important.


memory_limit
Sets a maximum amount of memory in bytes that a script is allowed to allocate. Resizing a 3000 x 2000 pixel image to 300 x 200 may take up to 32MB memory.


您可以验证Ubuntu的 php.ini的,也可以尝试 将图像库更改为 gdimagick

关于laravel - 将PNG另存为JPG时,图像干预会在背景上添加黑噪声,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62952108/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com