Laravel Add Watermark on Images

Hello dev, Today we are going to learn how to add watermark to images in laravel. This tutorial will cover on laravel add watermark on images.

We will share on laravel add watermark on images in laravel application. This tutorial is going to work with all version of laravel 5, laravel 6, laravel 7, laravel 8 and laravel 9. Many times we need to add watermark to our website images, so we can identify this all images by our website.

In this example, we will install intervention/image package and then we will create one simple route to adding image watermark in laravel app. so let’s follow bellow step to add image watermark in laravel.

Steps for Laravel Add Watermark on Images

  • Install intervention/image Package
  • Add Watermark to image

Also Read: How to Check Date is Today’s Date or not in Laravel Carbon?

Install intervention/image Package

The best way to install Intervention Image is quickly and easily with Composer.

To install the most recent version, run the following command.

composer require intervention/image

Intervention Image has optional support for Laravel and comes with a Service Provider and Facades for easy integration. The vendor/autoload.php is included by Laravel, so you don’t have to require or autoload manually. Just see the instructions below.

After you have installed Intervention Image, open your Laravel config file config/app.php and add the following lines.

In the $providers array add the service providers for this package.

Also Read: How to Get All env Variables in Laravel?

Integration in Laravel

Intervention Image has optional support for Laravel and comes with a Service Provider and Facades for easy integration. The vendor/autoload.php is included by Laravel, so you don’t have to require or autoload manually. Just see the instructions below.

After you have installed Intervention Image, open your Laravel config file config/app.php and add the following lines.

In the $providers array add the service providers for this package.

Intervention\Image\ImageServiceProvider::class

Add the facade of this package to the $aliases array.

'Image' => Intervention\Image\Facades\Image::class

Now the Image Class will be auto-loaded by Laravel.

Configuration

By default Intervention Image uses PHP’s GD library extension to process all images. If you want to switch to Imagick, you can pull a configuration file into your application by running one of the following artisan command.

Publish configuration in Laravel

php artisan vendor:publish --provider="Intervention\Image\ImageServiceProviderLaravelRecent"

Publish configuration in Laravel <= 4

php artisan config:publish intervention/image

In recent Laravel applications the configuration file is copied to config/image.php, in older Laravel 4 applications you will find the file at app/config/packages/intervention/image/config.php. With this copy you can alter the image driver settings for you application locally.

Also Read: Laravel Pagination Tutorial

Add Watermark to image

Here, I will create simple route and add watermark to image. so you need to add two images on your public “images” folder for testing.

make sure you have main.png and logo.png image on your images folder for demo. So let’s see bellow example.

Route::get('addWatermark', function()
{
    $img = Image::make(public_path('images/main.png'));
   
    /* insert watermark at bottom-right corner with 10px offset */
    $img->insert(public_path('images/logo.png'), 'bottom-right', 10, 10);
   
    $img->save(public_path('images/main-new.png')); 
   
    dd('Saved Image Successfully.');
});

Conclusion

Today, We had learn Laravel Add Watermark on Images. Hope this tutorial helped you with learning Laravel 9. If you have any question you can ask us at comment section below. If you like the tutorial please subscribe our YouTube Channel and follow us on social network Facebook and Instagram.

Also Read: Laravel Carbon Time Format AM PM Example Code

Leave a Reply