How to add text on image in laravel 5?

By Hardik Savani | January 30, 2016 | | 9885 Viewer | Category : Laravel


Share this post:



if you are use laravel and you want to add text on image or resize, crop image then we can do with "intervention/image" pakacke.

you have to just follow few step and you can add text on image.

Step 1 : you have to add package on your laravel project by using composer like :

composer require intervention/image

Step 2 : then you have to add provider path and alias path in config/app.php file like :

In $provides :

'Intervention\Image\ImageServiceProvider'

In $aliases :

'Image' => 'Intervention\Image\Facades\Image'

Step 3 : then you can use Image class in your 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'));

}

Now you can check image you find text in your image, if you also want to set font color, font size, font style then you 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'));

}