image
image copied to clipboard
How to remove white background in logos
I'm trying to remove the white background in logos to get a transparent icon, for example
on this image
Is .jpg, I want to remove white background (Only what's outside if is possible, otherwise removing all the white background)
I'm trying using this code
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;
}
but this is my result
the image lost color
what am I doing wrong? I feel that I am very close to achieving it, however, I need the icons to have color
In your function you're applying a mask on a black image, the result looks correct. You should try to add $logo to $new_image before applying the mask.

