PHP合并两张图片的实现

时间:2023-02-10 18:53:25

代码如下:

$bigImgPath = "./images/bg.jpg";
$qCodePath = "./images/thumb/$id.jpg";

$bigImg = imagecreatefromstring(file_get_contents($bigImgPath));
$qCodeImg = imagecreatefromstring(file_get_contents($qCodePath));

list($qCodeWidth, $qCodeHight, $qCodeType) = getimagesize($qCodePath);

imagecopymerge($bigImg, $qCodeImg, 239, 677, 0, 0, $qCodeWidth, $qCodeHight, 100);
 
list($bigWidth, $bigHight, $bigType) = getimagesize($bigImgPath);

imagejpeg($bigImg,'./images/'.$id.'.jpg');

imagejpeg输出图片,并保存。