Laravel 9
How to create a watermark on an image in Laravel 9

To create a watermark on an image in Laravel 9, you can use the intervention/image package. Here are the steps to do so:
- Install the intervention/image package by running the following command in your terminal:
composer require intervention/image
- After installing the package, open your controller where you want to create the watermark and add the following lines of code:
use Intervention\Image\Facades\Image;
- Now you can create a watermark on an image by using the
insert
method of the Intervention Image class. Here is an example code to create a watermark:
public function createWatermark() { $image = Image::make('path/to/image.jpg'); $watermark = Image::make('path/to/watermark.png'); // calculate the position of the watermark $x = $image->getWidth() - $watermark->getWidth() - 10; $y = $image->getHeight() - $watermark->getHeight() - 10; // insert the watermark $image->insert($watermark, 'bottom-right', $x, $y); // save the new image $image->save('path/to/new/image.jpg'); }
In the above example, the make
method is used to create an image object from the source image and the watermark image. The insert
method is used to insert the watermark on the image, and the save
method is used to save the new image.
You can customize the position of the watermark by changing the values of $x
and $y
. The bottom-right
parameter of the insert
method specifies the position of the watermark relative to the image.
I hope this helps!