gpt4 book ai didi

javascript - 将彩色 Logo 转换为纯白色 Logo

转载 作者:行者123 更新时间:2023-11-28 06:23:09 27 4
gpt4 key购买 nike

我有一个用户以 PNG 格式上传的 Logo 。

enter image description here

我的目标是将用户上传的 Logo 转换为白色。

像这样 - 这样它在较暗的背景下看起来不错。

enter image description here

我可以导出它并使用 Photoshop 获得我想要的东西,但我想以编程方式进行。

是否有任何 API/程序包可以帮助我实现这一目标?

我愿意接受任何建议。随意。


我试过了

PHP

<?php

$logoSrc = '/images/logo.png?q=<?php echo microtime();';
$logo = imagecreatefromstring($logoSrc);
$white = imagecolorallocate($logo, 255, 255, 255);
imagecolortransparent($logo, $white);

?>

IMG

<img class="logo-external" src="{{imagefilter($logo, IMG_FILTER_COLORIZE, 255, 255, 255)}}">

结果

imagecreatefromstring():数据不是可识别的格式

最佳答案

在 PHP 中,您可以使用 imagecolortransparent 删除空格:

$white = imagecolorallocate($img, 255, 255, 255);
imagecolortransparent($img, $white);

然后尝试使用 imagefilter使剩余图像变白:

imagefilter($img, IMG_FILTER_COLORIZE, 255, 255, 255)

关于javascript - 将彩色 Logo 转换为纯白色 Logo ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35445426/

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