Imagick - 将 PNG 转换为 JPG,透明背景变成黑色

发布于 2024-12-29 07:31:53 字数 552 浏览 1 评论 0原文

我希望我的背景最终变成白色。我查看了其他问题,但似乎没有一个答案能够真正解决这个问题。

我正在使用 Imagick 2.3 版,这就是我所拥有的:

$this->_object = new Imagick();
$this->_object->setResolution(300, 300);
$this->_object->readImage($fileRead);
$this->_object->setImageMatte(true);
$this->_object->setImageMatteColor("white");
$this->_object->setImageAlphaChannel(Imagick::ALPHACHANNEL_OPAQUE);

我已经尝试过了

setBackgroundColor, setImageBackgroundColor, composite over a white image

,但这些似乎都不起作用。有什么建议吗?

And I want my background to end up white instead. I've taken a look at the other questions and none of the answers seemed to really solve this problem.

I'm using Imagick version 2.3, and here's what I have:

$this->_object = new Imagick();
$this->_object->setResolution(300, 300);
$this->_object->readImage($fileRead);
$this->_object->setImageMatte(true);
$this->_object->setImageMatteColor("white");
$this->_object->setImageAlphaChannel(Imagick::ALPHACHANNEL_OPAQUE);

I've tried

setBackgroundColor, setImageBackgroundColor, composite over a white image

And none of these seem to work. Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南…巷孤猫 2025-01-05 07:31:53

jpg 扩展名不支持背景透明,您需要使用 png。对于其他网站,如果您有一个带有写入背景的 img,您可以使用以下代码将此颜色设置为透明:

    $route  = "MiOldJpgWriteBackground.jpg";
    $salida = 'MiNewTransparentFile.png';
    exec("convert $route $salida");
    exec("convert $salida -bordercolor white -border 1x1 \
         -alpha set -channel RGBA -fuzz 10% \
         -fill none -floodfill +0+0 white \
         -shave 1x1 $salida");
    exec("rm $route");

The jpg extension doesn't support transparency in background, you will need use png. For other site if you have for example one img with write background you could set this color in transparent with this code:

    $route  = "MiOldJpgWriteBackground.jpg";
    $salida = 'MiNewTransparentFile.png';
    exec("convert $route $salida");
    exec("convert $salida -bordercolor white -border 1x1 \
         -alpha set -channel RGBA -fuzz 10% \
         -fill none -floodfill +0+0 white \
         -shave 1x1 $salida");
    exec("rm $route");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文