Laravel Generate Image With Text Example




Laravel Generate Image With Text Example

Hi Friends,

I am going to explain you example of laravel generate image with text example. Inside this article we will see the how to create image with text using form in laravel. This article contains a very classified information about the basic concept of laravel generate image using form with text.

We will see the concept of how to create image from text in laravel php with external library. This example use to how to write text on an image in laravel and save it?

So let's start following step.

Step : 1 - Installation of Laravel Application

Use this command then download laravel project setup :

composer create-project --prefer-dist laravel/laravel blog

Step : 2 - You have to add package on your laravel project by using composer like

composer require intervention/image

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


'providers' => [



'aliases' => [

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


Step 4 : Create route



use Illuminate\Support\Facades\Route;



| 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('/generate-image-text', array('as'=> 'generate.image.text', 'uses' => 'ImageController@generateImageText'));

Route::post('generate-image-text-store', array('as'=> '', 'uses' => 'ImageController@generateImageTextStore'));

Step 5 : Create Controller

php artisan make:controller ImageController



namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Image;

class ImageController extends Controller



* Generate Image View


* @return void


public function generateImageText(){

return view('index');



* Store Generate Image


* @return void


public function generateImageTextStore(Request $request){

$text = $request->input('text');

if($request->file('name') != ""){

$file = $request->file('name');

$file_name = time().'_'.$file->getClientOriginalName();

$img = Image::make($file);









return $img->response("jpg");


return back();



Step 6 : Create blade file


<!DOCTYPE html>



<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title>Laravel Generate Image With Text -</title>

<link rel="stylesheet" href="">



<div class="container">

<div class="row justify-content-md-center mt-5">

<div class="col-md-8 border p-4 mt-5">

<h3>Laravel Generate Image With Text -</h3>

{{ Form::open(array('route' => 'generateImageTextStore','method' => 'post','files' => true ,'class' => 'mt-4')) }}


<div class="form-group">

{{ Form::label('Enter Text:') }}

{{ Form::textarea('text','',array('class' => 'form-control','rows' => '3','placeholder' => 'Enter Text Here ...')) }}


<div class="form-group">

{{ Form::label('Enter Image:') }}

{{ Form::file('name',array('class' => 'form-control')) }}


{{ Form::submit('Submit',array('class' => 'btn btn-primary mt-2')); }}

{!! Form::close() !!}







I hope it can help you...