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';
    }

  

猜你喜欢

转载自www.cnblogs.com/hhzy/p/12396267.html