2013-05-03 37 views
1

1次重複我想利用具有透明度的圖像,然後覆蓋上一個重複用於第一圖像的寬度和長度的60×60(任意尺寸)圖像的頂部。 ..合併兩個圖像GD庫,具有在背景

所以基本上使用圖像2作爲重複的背景圖像該圖像1是上的頂部。

編輯:

好了,所以就用一招小馬的解決方案,但試圖修改它以出的矩形的創建正方形圖像,如果寬度小於高度,但不拉伸原圖像,而不是集中。我能夠將圖像居中,但重疊圖像停止後,重複背景不會繼續重複。

下面是代碼:

<?php 

    $overlay = imagecreatefrompng('../images/' . $_REQUEST['overlay']); 

    $repeating = '../images/' . $_REQUEST['repeating']; 
    $ext = explode('.', $_REQUEST['repeating']); 
    $ext = strtolower($ext[1]); 


    if ($ext == 'gif') 
     $repeating = imagecreatefromgif($repeating); 
    elseif ($ext == 'png') 
     $repeating = imagecreatefrompng($repeating); 
    elseif ($ext == 'jpg' || $ext == 'jpeg') 
     $repeating = imagecreatefromjpeg($repeating); 


    $w   = imagesx($overlay); 
    $h   = imagesy($overlay); 
    if ($w < $h) 
     $w = $h; 

    $output = imagecreatetruecolor($w, $h); 
    imagealphablending($output, true); 


    imagesettile($output, $repeating); 
    imagefill($output, 0, 0, IMG_COLOR_TILED); 
    imagedestroy($repeating);  

    $offsetx = ($w - imagesx($overlay))/2; 

    imagecopy($output, $overlay, $offsetx, 0, 0, 0, $w, $h); 
    imagedestroy($overlay); 


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



    ?> 

編輯2:

疊加:http://72.167.52.68/~viisi/ebaylist/images/back_test2.png

重複:http://72.167.52.68/~viisi/ebaylist/images/back_test.gif

預期結果(但繼續在整個圖像重複):http://72.167.52.68/~viisi/ebaylist/image/previewImage.php?overlay=back_test2.png&repeating=back_test.gif

+0

維塔利嗨,偉大的想法 - 活躍起來,編寫一些代碼,它張貼在這裏,如果你需要幫助!我認爲PHP的GD函數將是一個好的開始。 – michi 2013-05-03 01:22:08

+1

明天當我回到辦公室時,我會開始這件事,一旦我有事情就會發布結果。 – 2013-05-03 01:23:55

回答

3
$overlay = imagecreatefrompng('/path/to/transparent/image.png'); 
$repeating = imagecreatefrompng('/path/to/repeating/image.png'); 

// create a new image matching overlay size 
$w = imagesx($overlay); 
$h = imagesy($overlay); 
$output = imagecreatetruecolor($w, $h); 
imagealphablending($output, true); 
imagesavealpha($output, true); 

// tile repeating image on it 
imagesettile($output, $repeating); 
imagefill($output, 0, 0, IMG_COLOR_TILED); 
imagedestroy($repeating);  

// now add overlay on top 
imagecopy($output, $overlay, 0, 0, 0, 0, $w, $h); 
imagedestroy($overlay); 

// send to screen 
header('Content-Type: image/png'); 
imagepng($output); 
imagedestroy($output); 
+0

我對我的問題做了一個編輯,你可以試一試嗎? – 2013-05-05 06:30:19

+0

如果您發佈兩個圖像,另一個在第二編輯預期輸出 – 2013-05-05 09:58:09

+0

圖像。 – 2013-05-05 12:22:18