lundi 15 août 2016

How to remove white background from image using Intervention Image

A user uploaded image file with handwriting in black ink. I want to remove the background and preserve the handwriting as a new .png image. Using Intervention Image there is a feature called trim() that sounds like it should do exactly this, but doesn't give the expected results.

Code:

$file = $request->file('employee_signature');

$name = $employee->givenname.'_'.$employee->surname.'_Signature.png';

$new_image = Intervention::make($file)->trim()->save('images/signatures/'.$name);

return $new_image;

$new_image should return an image called "First_Last_Signature.png" and only have the black handwriting. With my current code it doesn't trim the white background. I can confirm it's being processed because when I upload a .jpg it is saved as a .png in the specified directory.

There is a suggestion on GitHub that says the fill() should work, but I cannot get it to.

There is a solution here on SOF that does exactly what I want, but not using the Intervention Image library: LINK

I am currently using Imagemagick, however the GD library is available as well, although the Intervention Image docs do say that GD will use a lot of resources.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire