PHP 兩張圖片合並


 

將前景圖放在背景圖的指定位置

public function combineimg($backimg,$upimg)
    {
        $dst_path = $backimg;  // 背景圖
        $src_path = $upimg;   // 前景圖
        //創建圖片的實例
        $dst = imagecreatefromstring(file_get_contents($dst_path));
        $src = imagecreatefromstring(file_get_contents($src_path));
        // 把前圖片的白色背景設為透明
        imagecolortransparent($src, imagecolorallocate($src, 255, 255, 255));
        //獲取水印圖片的寬高
        list($src_w, $src_h) = getimagesize($src_path);
        //將水印圖片復制到目標圖片上
        imagecopymerge($dst, $src, 235, 720, 0, 0, $src_w, $src_h, 100);
        $newpath = IA_ROOT."/attachment/"; 
        //生成圖片
        imagepng($dst,$newpath.'test2.png');//銷毀
        imagedestroy($dst);
        imagedestroy($src);

        return $res='test2.png';
    }

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM