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());
Start here http://php.net/manual/en/book.image.php
– Neuber Oliveira