php合成图片

<?php
/**
 * Created by PhpStorm.
 * User: 13sai
 * Date: 2018/12/7
 */


header("Content-type: image/png");
//ob_clean();
//
$path_2 = D:workdata/2.png;
$path_1 = D:workdata/1.png;
$info2 = getimagesize($path_2);
$info1 = getimagesize($path_1);

function getImage($ext, $img)
{
    switch ($ext) {
        case png :
            $ret = imagecreatefrompng($img);
            break;
        case jpeg:
            $ret = imagecreatefromjpeg($img);
            break;
        case gif:
            $ret = imagecreatefromgif($img);
            break;
        default:
            throw new \Exception(不能识别的图片格式);
            break;
    }
    return $ret??;
}

//获取图片扩展名
$type1 = image_type_to_extension($info1[2],false);
$type2 = image_type_to_extension($info2[2],false);


$image_1 = getImage($type1, $path_1);
$image_2 = getImage($type2, $path_2);

imagecopy( $image_1, $image_2, 50, 70, 0, 0, $info2[0], $info2[1] );
// 输出
imagepng($image_1, D:picscompose.png);

imagedestroy($image_1);
imagedestroy($image_2);

php合成图片
https://github.13sai.com/2018/12/13/172/
作者
13sai
许可协议