2014-10-02 32 views
0

我會在另一個圖像中放置一個徽標圖像,這兩個圖像是PNG,我嘗試使用imagecopy和imagecopymerge這兩個函數但沒有任何關係,我沒有看到結果我打開磁盤上的圖像,但是這兩個函數都返回true。有人能幫助我,這裏是我使用的代碼:PHP:Imagecopy和Imagecopymerge不能使用兩個png

 $data = substr($_POST['imageData'], strpos($_POST['imageData'], ",") + 1); 
    $decodedData = base64_decode($data); 
    $img = "assets\\images\\simulation\\user\\img777.png"; 
    $srcpath = "assets\\images\\logo.png"; 
    fp = fopen($img , 'wb'); 
    fwrite($fp, $decodedData); 
    fclose($fp);//work until this place 
    $dest =imagecreatefrompng($img); 
    $src =imagecreatefrompng($srcpath); 
    imagecopy ($dest,$src, 0, 0, 0, 0, imagesx($src),imagesy($src)); 

    // or imagecopymerge ($dest,$src, 0, 0, 0, 0, imagesx($src),imagesy($src), $pct); with $pct =0 or 50 

    /*or i have also try : $cut = imagecreatetruecolor(imagesx($src),imagesy($src)); 
     imagecopy($cut, $dest, 0, 0, 0, 0, imagesx($src),imagesy($src)); 
     imagecopy($cut, $src, 0, 0, 0, 0, imagesx($src),imagesy($src)); 
     imagecopymerge ($dest,$cut, 0, 0, 0, 0, imagesx($src),imagesy($src), $pct); with $pct =0 or 50*/ 

這裏有圖像logo.png一個例子:http://upload.wikimedia.org/wikipedia/commons/4/48/EBay_logo.png

下面是其他image.png:http://www.noelshack.com/2014-40-1412264764-img68634dxn777.png

結果這是相同的image.png ...

你能幫助我,謝謝。

+0

我解決了這個問題,下面的代碼: – 2014-10-03 09:20:30

回答

0

我解決了這個問題,下面的代碼:

imagealphablending($dest, true); 
    imagealphablending($src, true); 
    imagesavealpha($dest, true); 
    imagesavealpha($src, true); 
    imagecopy ($dest,$src, 5, imagesy($dest) - (imagesy($src)+5), 0, 0,imagesx($src),imagesy($src)); 
    imagealphablending($dest, true); 
    imagesavealpha($dest, true); 
    imagepng($dest,$img); 
    imagedestroy($dest); 
    imagedestroy($src); 

代替:

$dest =imagecreatefrompng($img); 
    $src =imagecreatefrompng($srcpath); 
    imagecopy ($dest,$src, 0, 0, 0, 0, imagesx($src),imagesy($src)); 
相關問題