3

I'm trying to remove the white background in logos to get a transparent icon, for example

on this image

enter image description here

Is .jpg, I want to remove withe background (Only what's outside if is possible, otherwise removing all the white background)

I'm trying using laravel intervention image with 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

enter image description here

the image lost color (black colored)

what am I doing wrong? I feel that I am very close to achieving it, however, I need the icons to have color

Andre
  • 628
  • 6
  • 25

1 Answers1

0
$img = Image::canvas(800, 600);

Call canvas method without background color. See more on http://image.intervention.io/api/canvas

Shahrukh
  • 399
  • 2
  • 15