Watermark image on Laravel 5.2

Asked

Viewed 603 times

3

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

The image is sent by a form and through the $request->file('img') in the controller i add in the folder and the name of the image in the database, but how to put this water mark in png in the image within the method in the controller?

mergeimage() php does not work.

Thank you

1 answer

2

Use the package Intervention/image, it easily integrates into the Laravel framework by following the step by step installation and after 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 on array of providers more that 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 on the command line

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

How to work with this package:

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

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

In your specific case, when saving the image to disk, press again and call method Insert with the folder parameter and file name with the extension .png to create the mask 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 directly when sending the photo:

Image::make($request->file('img')->getPathname());

Browser other questions tagged

You are not signed in. Login or sign up in order to post.