问题描述
我正在尝试删除徽标中的白色背景以获得透明图标,例如
是.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;
}
但这是我的结果
图像丢失颜色(黑色)
我做错了什么?我觉得我很接近实现它,但是,我需要图标有颜色
解决方法
$img = Image::canvas(800,600);
调用没有背景颜色的画布方法。 在 http://image.intervention.io/api/canvas
上查看更多信息