Home > PHP Framework > Laravel > body text

Add image watermark in Laravel

花姐姐
Release: 2020-05-06 14:09:36
forward
3132 people have browsed it

Add image watermark in Laravel

In this article, we will learn how to add watermarks to images in Laravel5.8 programs. To do this, we need to use the composer package of intervention image . We can add text or image watermarks. For more usage methods, you can see the content below.

Image watermark allows us to add copyright information to the image. Or, sometimes, we want users to know that the picture comes from our website. In this article, we will give an example of simply adding a watermark to an image in a Laravel 5.8 project.

Add watermark to pictures. We will first install the intervention/image extension package, and then in the Laravel project we will create a simple route to add watermarks to images. Next, let us follow the steps to learn how to add watermarks to images in the Laravel 5.8 project.

Step one: Install intervention/image Extension package

In the first step, I installed composer of intervention/image Extension package to add watermark function. You can use the following command to install

composer require intervention/image

After the installation is complete, we need to set the service provider and alias. For this, we need Modify the config/app.php file and add the following code to the corresponding array.

‘providers’ => [
Intervention\Image\ImageServiceProvider::class
]
‘aliases’ => [
 ‘Image’ => Intervention\Image\Facades\Image::class
]
Copy after login

Note: In fact, after Laravel 5.5, we no longer need to perform such operations. So this step can actually be omitted.

Step 2: Add watermark to the image

Here, a controller is created (you can use a simple route) to add the watermark to the image. You need to add 2 pictures to the images directory in the public directory to test.

In my test image folder images, there is a main image main.png and a watermark image watermark.png.

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

This is the complete tutorial on adding image watermarks in Laravel 5.8.

Recommended learning: Laravel

The above is the detailed content of Add image watermark in Laravel. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!