2013-12-11 64 views
0

我已刪除了我原來的問題,我已成功地部分地得到這個工作,我有什麼是7張,如何使用GD庫將多個圖像合併在一起?

https://dl.dropboxusercontent.com/u/58586640/layer1.png https://dl.dropboxusercontent.com/u/58586640/layer2.png https://dl.dropboxusercontent.com/u/58586640/layer3.png https://dl.dropboxusercontent.com/u/58586640/layer4.png https://dl.dropboxusercontent.com/u/58586640/layer5.png https://dl.dropboxusercontent.com/u/58586640/layer6.png https://dl.dropboxusercontent.com/u/58586640/layer7.png

這些圖像當放置在彼此的頂部時應該創建一個完美插入在一起的圖像。

目前的結果我已經是,

https://dl.dropboxusercontent.com/u/58586640/Screen%20Shot%202013-12-11%20at%2018.31.57.png

正如你可以看到它的工作原理幾乎完全而是層2可能是沒有被複制或沒有得到的阿爾法正確保存。我不知道我在做什麼錯誤的,因爲所有其他各層看起來做工精細,這是未來在黑色的圖像,

https://dl.dropboxusercontent.com/u/58586640/layer3.pnghttps://dl.dropboxusercontent.com/u/58586640/layer4.png

這裏是我當前的代碼,

<?php 

$images = array('img/layer1.png', 'img/layer2.png', 'img/layer3.png', 'img/layer4.png', 'img/layer5.png', 'img/layer6.png', 'img/layer7.png'); 

// foreach($images as $i) { 
// var_dump(file_exists($i)); 
// } 

// Allocate new image 

$img = imagecreatetruecolor(704, 469); 

// Make alpha channels work 

imagealphablending($img, true); 
imagesavealpha($img, true); 

foreach($images as $fn) { 

    // Load image 
    $cur = imagecreatefrompng($fn); 
    imagealphablending($cur, true); 
    imagesavealpha($cur, true); 

    // Copy over image 
    imagecopy($img, $cur, 0,0,0,0, 704, 469); 

    // Free memory 
    imagedestroy($cur); 

} 

header('Content-Type: image/png'); 
imagepng($img); 

正如你所看到的,我已經檢查過以確保這些文件存在,並且它們這樣做必須是GD問題,任何人都有想法?

回答

0

有趣我昨天做了這件事,這裏是我如何使用靜態背景圖層和組合前生成的QR碼做的。

$template = imagecreatefrompng("./images/asset_barcode_template.png"); 
//QR created fine assemble final image 
$qrimage = imagecreatefrompng($this->qrfilename); 
//final image assembled just fine 
imagecopy($template, $qrimage, 230, 6, 0, 0, 106, 106); 
imagepng($template,$filename,0,PNG_NO_FILTER);