0

I want to make a image from multiple image.In my image list have maximum 6 image.i want to add all image side by side.as example


1st image          |      2nd image

3rd image          |      4th image

5th image          |      6th image

I am writing a code that makes image Vertically.

my code

<?php



$numberOfImages = 6;
$x = 940;
$y = 920;
$background = imagecreatetruecolor($x, $y*6);


$firstUrl = 'e.jpg';

$secondUrl = 'f.jpg';

$thirdUrl = 'f.jpg';

$fourthUrl = 'e.jpg';

$fiveUrl = 'f.jpg';

$sixUrl = 'f.jpg';

$outputImage = $background;

$first = imagecreatefromjpeg($firstUrl);
$second = imagecreatefromjpeg($secondUrl);
$third = imagecreatefromjpeg($thirdUrl);



imagecopymerge($outputImage,$first,0,0,0,0, $x, $y,100);
imagecopymerge($outputImage,$second,0,$y,0,0, $x, $y,100);
imagecopymerge($outputImage,$third,0,$y*2,0,0, $x, $y,100);

imagejpeg($outputImage, APPLICATION_PATH .'test.jpg');

imagedestroy($outputImage);




?>

But i want to placed image dynamically cause image item could be 4 or 5 or 6 or 1 or 2 or 3

But how?

WBT
  • 2,249
  • 3
  • 28
  • 40
Hasib BD
  • 1
  • 2
  • Maybe this answer helpful: http://stackoverflow.com/questions/23121488/php-gd-merge-multiple-images-in-tiled-layout – Jesus Dec 02 '14 at 20:58

1 Answers1

1

Check out Merge two images in php

Adapt that function to either put two images side by side (taking two parameters, each images) and also adapt it to put three images vertically (as it starts with two, you're just adding a third). This second adaptation would take three parameters of the three images to join.

Then call the functions, nesting one in the other, such as:

join3(join2($firstURL, $secondURL), 
      join2($thirdURL, $fourthURL), 
      join2($fifthURL, $sixthURL));

and you can set your URL parameters to whatever you want to dynamically call the function.

Community
  • 1
  • 1
WBT
  • 2,249
  • 3
  • 28
  • 40