DEV Community

Cover image for How to add watermark on an image in Laravel 5.8 Step by Step
Anil Loutombam
Anil Loutombam

Posted on

How to add watermark on an image in Laravel 5.8 Step by Step

In this blog post, we will learn, how to add watermark to an image in Laravel 5.8 application, to add watermark to images we will use the intervention image composer package in Laravel 5.8. we can add images or text as a watermark on the image in Laravel. For more docs, you can follow them.
Intervention Image.

To make a watermark on an image. we will install intervention/image package and then we will create one simple route to adding image watermark in the Laravel app. so let’s follow the below step to add image watermark in Laravel 5.8.

Step:1 Install intervention/image Package.

In the first step, I install an intervention/image composer package for adding watermark to the image in Laravel 5.8. to install a package using the following command.

composer require intervention/image

After installation, we need to set providers and alias, to do that we need to follow some steps… go to your project and search.

config/app.php

providers => [
Intervention\Image\ImageServiceProvider::class
]
aliases => [
 Image => Intervention\Image\Facades\Image::class
]
Enter fullscreen mode Exit fullscreen mode

Step:2 Add Watermark to image

Here, I created a controller(you can use a simple route) to add a watermark to the image. so you need to add two images on your public “images” folder for testing purposes.

Here I use two images one for the main image and a second image for watermark so I have a main.png and watermark.png image on your images folder for demo.

public function addWatermark(){
   $img = Image::make(public_path('images/main.png'));    
   $img->insert(public_path('watermark.png'),'bottom-right',10, 10); 
   $img->save();
}
Enter fullscreen mode Exit fullscreen mode

So here we completed tutorials on How to Add Watermark on an Images in Laravel 5.8 step by step.

Oldest comments (0)