How To Merge Two Images In laravel?




How To Merge Two Images In laravel?

Hi Friends,

I am going to explain you example of how to merge two images in laravel?. Inside this article we will see the how to combine two images in php / laravel. This article contains a very classified information about the basic concept of laravel | imagecopymerge() Function.

We will see the concept of Join two images intervention/image. This example use to create laravel multiple upload images and displaying on one view.

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 : 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('merge-img', array('as'=> 'merge.img', 'uses' => 'ImageController@mergeImg'));

Step 3 : Create Controller

php artisan make:controller ImageController



namespace App\Http\Controllers;

use Illuminate\Http\Request;

class ImageController extends Controller



* Display a listing of the resource.


* @return \Illuminate\Http\Response


public function mergeImg()


$image1 = public_path('/images/frame1.jpg');

$image2 = public_path('/images/frame2.jpg');

list($width,$height) = getimagesize($image2);

$image1 = imagecreatefromstring(file_get_contents($image1));

$image2 = imagecreatefromstring(file_get_contents($image2));




$masterImg = imagepng($image1,'merged.png');




Frame : 1

Frame : 2


I hope it can help you...