2014-12-02 42 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參數。