//加载正反面图片
$frontImage=imagecreatefromjpeg('front.jpg');//替换为实际的正面图片路径
$backImage=imagecreatefromjpeg('back.jpg');//替换为实际的反面图片路径
//获取正反面图片的宽度和高度
$frontWidth=imagesx($frontImage);
$frontHeight=imagesy($frontImage);
$backWidth=imagesx($backImage);
$backHeight=imagesy($backImage);
//创建一个新的画布,宽度为两张图片的最大宽度,高度为正反面图片高度之和
$mergedWidth=max($frontWidth,$backWidth);
$mergedHeight=$frontHeight+$backHeight;
$mergedImage=imagecreatetruecolor($mergedWidth,$mergedHeight);
//将正反面图片垂直堆叠在一起
imagecopy($mergedImage,$frontImage,0,0,0,0,$frontWidth,$frontHeight);
imagecopy($mergedImage,$backImage,0,$frontHeight,0,0,$backWidth,$backHeight);
//保存合并后的图片
imagejpeg($mergedImage,'merged.jpg');//替换为保存合并后图片的路径
//释放内存
imagedestroy($frontImage);
imagedestroy($backImage);
imagedestroy($mergedImage);
|