How to add text on image in Laravel?

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Today now in this tutorial i will show you how to add text on image in laravel application. if we are use laravel and we need to add text on image or need to resize, crop image then here we can do this with “intervention/image” package

If we need to just follow few step and then we can add text on image.

Step 1 :

At first we need to add a new package on your laravel project by using composer as like :

composer require intervention/image
Step 2 : 

So then we need to add provider path and alias path in config/app.php file as like :

In $provides :

'Intervention\Image\ImageServiceProvider'

In $aliases :

'Image' => 'Intervention\Image\Facades\Image'
Step 3 : 

Then we can use Image class in our controller function like this :

 public function makeimage()  
    {  
       $img = Image::make(public_path('images/hardik.jpg'));  
       $img->text('This is a example ', 120, 100);  
       $img->save(public_path('images/hardik3.jpg'));  
    }  

So now we can check image we find text in our image, if we also want to set a font color, font size, font style then we can set this way :

public function makeimage()  
    {  
       $img = Image::make(public_path('images/hardik.jpg'));  
       $img->text('This is a example ', 120, 100, function($font) {  
          $font->file(public_path('path/font.ttf'));  
          $font->size(28);  
          $font->color('#e1e1e1');  
          $font->align('center');  
          $font->valign('bottom');  
          $font->angle(90);  
      });  
       $img->save(public_path('images/hardik3.jpg'));  
    }

Read Also : How to Open Link in New Tab on Click in javascript ?

Thanks for read. I hope it help you. For more you can follow us on facebook.

About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →