Watermark on image in laravel 5.2

3

Hello, does anyone know how I could do that every image that is uploaded in laravel has a watermark?

The image is sent by a form and through $request->file('img') in the controller I add in the folder and the name of the image in the bank, but how to put that watermark in png in the image inside of the method in controller ?

mergeimage() of php does not work.

Thank you

    
asked by anonymous 01.09.2016 / 07:39

1 answer

2

Use the intervention / image package, it easily integrates with the Laravel framework by following the step-by-step installation and then integration >.

Step by step

$ php composer.phar require intervention/image

After installing the package in your Laravel, go to config/app.php and add in the array of providers plus this line:

Intervention\Image\ImageServiceProvider::class

and to facilitate type in array of $aliases

'Image' => Intervention\Image\Facades\Image::class

and to finish the installation and operation of the package type in the command line

$ php artisan vendor:publish --provider="Intervention\Image\ImageServiceProviderLaravel5"

Working with this package:

Route::get('/', function()
{
    $img = Image::make('foo.jpg')->resize(300, 200);

    return $img->response('jpg');
});

In your specific case, when burning the disk image, press again and call the insert method with the folder parameters and name the file with the .png extension to create the mascara in your image and have it saved again.

Example:

// open an image file
$img = Image::make('public/foo.jpg');

// now you are able to resize the instance
$img->resize(320, 240);

// and insert a watermark for example
$img->insert('public/watermark.png');

// finally we save the image as a new file
$img->save('public/bar.jpg');

Source: Intervention Image

You can also use it directly when sending the photo:

Image::make($request->file('img')->getPathname());
    
06.09.2016 / 21:16