Home > Backend Development > PHP Tutorial > How to add watermark to images in Laravel?

How to add watermark to images in Laravel?

藏色散人
Release: 2023-04-06 11:08:02
Original
5622 people have browsed it


#In this article, we will introduce how to add watermarks to images in laravel 5.8. We will add watermark to images using intervention/image package in laravel 5. We can add image or text as watermark.

How to add watermark to images in Laravel?

In this example, we will install the intervention/image package, and then we will create a simple Route to add image watermark.

Installationintervention/image Package

We need to install intervention/image package to add watermark to the image, so you can use the following command After installing:

composer require intervention/image
Copy after login

, you need to set up providers and aliases.

config/app.php

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

Add watermark to image

Here I will create a simple Route and add watermark to the image. Therefore, you need to add two images to your public "images" folder for testing.

Make sure you have main.png and logo.png images in your images folder for demonstration purposes.

Let’s look at the following example.

Route::get('addWatermark', function()
{
    $img = Image::make(public_path('images/main.png'));
   
    /* 在右下角添加水印,偏移量为10px */
    $img->insert(public_path('images/logo.png'), 'bottom-right', 10, 10);
   
    $img->save(public_path('images/main-new.png')); 
   
    dd('成功保存图像。');
});
Copy after login

This article is about how to add watermarks to images in Laravel. I hope it will be helpful to friends who need it!


The above is the detailed content of How to add watermark to images in Laravel?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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