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:

  1. Install the intervention/image package by running the following command in your terminal:
composer require intervention/image
  1. 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;
  1. 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

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!


A programmer who cares about programming matters for the web application, mobile application, and servers and their protection

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Check Also
Back to top button