2014-12-02 78 views
0

合并我要让来自多个image.In我的图像列表中有最大的6个image.i一个图像想side.as例如,要添加的所有图像侧PHP图片来自多个图像


1st image   |  2nd image 

3rd image   |  4th image 

5th image   |  6th image 

我正在写一个代码,使图像垂直。

我的代码

<?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); 




?> 

但我想放置的图像动态地导致图像项可以是4或5或6或1或2或3

但如何?

+0

也许这个答案有帮助: http://stackoverflow.com/questions/23121488/php-gd-merge-multiple-images-in-tiled-layout – Jesus 2014-12-02 20:58:56

回答

1

退房Merge two images in php

适应该功能,要么把两个图像并排(取两个参数,每个图像),并适应它把三个图像垂直(因为它有两个开始,你只是增加第三个)。这第二次适应将需要三个图像的三个参数加入。

然后调用的函数,一个嵌套在其他,如:

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

,你可以设置任何你想要动态调用函数的URL参数。