我想去掉标志中的白色背景,获得透明图标,例如:
这张图片:
它是 .jpg 格式,我想移除白色背景(如果可能,只移除外面的部分;否则移除所有白色背景)。
我正在尝试使用 Laravel 的 intervention image 通过以下代码实现:
public function resizeImage($logo, $placeName, $domain)
{
$mask = Image::make($logo)
->contrast(100)
->contrast(50)
->trim('top-left', null, 40)
->invert(); // invert it to use as a mask
$new_image = Image::canvas($mask->width(), $mask->height(), '#000000')
->mask($mask)
->resize(32,32, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
})
->encode('png', 100);
$route = $domain . '/favicon/favicon.png';
Storage::disk('gcs')
->put($route, $new_image);
$route = Storage::disk('gcs')
->url($route);
return $route;
}
但这是我的结果
图像失去了颜色(黑色)
我做错了什么?我感觉我离成功很近了,但是我需要让图标有颜色。