Laravel Image Text Watermarking Tutorial

Jul 01, 2021 . Admin

Hello Friends,

Now let's see example of how to image text watermarking in laravel. This is a short guide on laravel if image text watermarking. We will use how to use image text watermarking in laravel. Here you will learn how to use image text watermarking in laravel. Let's get started with how to image text watermarking in laravel.

Here i will give you many example how you can image text watermarking in laravel.

Step 1 : Install Laravel 8

we need to get fresh laravel 8 version application So let's open terminal and run bellow command to install fresh laravel project.

composer create-project --prefer-dist laravel/laravel blog
Step 2 : Install composer require package

Second step to install composer package('intervention/image') in just following command through.

composer require intervention/image
Step 3 : Configure package

Now we need to add provider path and alias path in config/app.php file

Path: config/app.php

return [
    $provides => [
    $aliases => [
        'Image' => Intervention\Image\Facades\Image::class,
Step 4 : Add Route

Now, we will add routes file so first add bellow route in your routes.php file.

Path: routes\web.php

    use Illuminate\Support\Facades\Route;
    use App\Http\Controllers\PhotoFileController;

    | Web Routes
    | Here is where you can register web routes for your application. These
    | routes are loaded by the RouteServiceProvider within a group which
    | contains the "web" middleware group. Now create something great!

        Route::get('file-upload', [PhotoFileController::class, 'index'])->name('photo');
        Route::post('add-watermark', [PhotoFileController::class, 'photoFileUpload'])->name('photo.watermark');
Step 5 : Create Controller

Fifth step to create a PhotoFileController in just following command through.

php artisan make:controller PhotoFileController

Path: app\Http\Controllers\PhotoFileController.php


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Image;

class PhotoFileController extends Controller
     * Write code on Method
     * @return response()
    public function index()
        return view('photo');
     * Write code on Method
     * @return response()
    public function photoFileUpload(Request $request)
        $this->validate($request, [
            'file' => 'required|image|mimes:jpg,jpeg,png,gif,svg|max:4096',

        $photo = $request->file('file');
        $input['file'] = time().'.'.$photo->getClientOriginalExtension();
        $imgFile = Image::make($photo->getRealPath());
        $imgFile->text('© 2016-2020 - All Rights Reserved', 120, 100, function($font) { 

        return back()
            ->with('success','File successfully uploaded.')
Step 5 : Blade File and Create Upload directory

In this last step we will create resizePhoto.blade.php file for photo upload form and manage error message and also success message.

Path: resources\views\photo.blade.php

<!DOCTYPE html>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link href="" rel="stylesheet">
        <title>Laravel Image Text Watermarking Tutorial</title>
        <div class="container mt-4" style="max-width: 600px">
            <h2 class="mb-5">Laravel Image Text Watermarking Example</h2>
            <form action="{{route('photo.watermark')}}" enctype="multipart/form-data" method="post">
                @if ($message = Session::get('success'))
                    <div class="alert alert-success">
                        <strong>{{ $message }}</strong>

                    <div class="col-md-12 mb-3 text-center">
                        <strong>Manipulated photo:</strong><br />
                        <img src="/uploads/{{ Session::get('fileName') }}" width="600px"/>
                @if (count($errors) > 0)
                    <div class="alert alert-danger">
                            @foreach ($errors->all() as $error)
                            <li>{{ $error }}</li>
                <div class="mb-3">
                    <input type="file" name="file" class="form-control"  id="formFile">
                <div class="d-grid mt-4">
                    <button type="submit" name="submit" class="btn btn-primary">
                        Upload File

After, last create directory in your public folder uploads.

Now run bellow command for quick run:

php artisan serve

Now open bellow URL on your browser:


It will help you....