2013-02-03 16 views
0

我有一個圖像已被分解成部分,64行64列。每張圖片都是256x256px。圖像都是PNG。它們被命名爲「Image - 。png」,例如「Image-3-57」。行和列的編號從0開始,而不是從1開始。重新組合一個零碎的圖像

我怎樣才能將它重新組合到一個圖像中?理想情況下使用BASH和工具(我是一個系統管理員),儘管PHP也是可以接受的。

+0

如果您想要使用bash命令執行操作,您可能會對http://superuser.stackexchange.com/有更好的運氣。你可以看看imagemagick,我很確定它可以用它來做到這一點。 –

回答

0

那麼,它不是很複雜,如果你想使用PHP。你需要的只是幾個圖像槍 - imagecreateimagecopy。如果您的PNG是半透明的,您還需要imagefilledrectangle來創建透明背景。 在下面的代碼中,我依賴於事實,即所有的塊都具有相同的大小 - 所以像素大小必須能夠除以塊的數量。

<?php 
$width = 256*64; //height of the big image, pixels 
$height = 256*64; 
$chunks_X = 64; //Number of chunks 
$chunks_Y = 64; //Same for Y 
$chuk_size_X = $width/$chunks_X; //Compute size of one chunk, will be needed in copying 
$chuk_size_Y = $height/$chunks_Y; 

$big = imagecreate($width, $height); //Create the big one 
for($y=0; $y<$chunks_Y; $y++) { 
    for($x=0; $x<chunks_X; $x++) { 
    $chunk = imagecreatefrompng("Image-$x-$y.png"); 
    imagecopy($big, $chunk, 
       $x*$chuk_size_X, //position where to place little image  
       $y*$chuk_size_Y, 
       0,     //where to copy from on little image 
       0, 
       $chuk_size_X,  //size of the copyed area - whole little image here 
       $chuk_size_Y, 
    ); 
    imagedestroy($chunk);  //Don't forget to clear memory 
    } 
} 
?> 

這只是一個草案。我不確定所有的xs和ys以及ather的細節。它已經很晚了,我很累。