php 合并身份证正反面图片为一张图片
$bg = imagecreatetruecolor(600, 750);
$white = imagecolorallocate($bg, 255, 255, 255);
imagefill($bg, 0, 0, $white); //绘制底色为白色
$z_url = 'https://cdn.learnku.com/uploads/avatars/93845_1644981045.jpeg';
$f_url = 'https://cdn.learnku.com/uploads/avatars/93845_1644981045.jpeg';
$z_img = imagecreatefromjpeg($z_url); //正面图片
$f_img = imagecreatefromjpeg($f_url); //反面图片
list($z_width, $z_height, $z_type, $z_attr) = getimagesize($z_url);
list($f_width, $f_height, $f_type, $f_attr) = getimagesize($f_url);
imagecopyresampled($bg, $z_img, 10, 10, 0, 0, 580, 360, $z_width, $z_height);//返回布尔值
imagecopyresampled($bg, $f_img, 10, 380, 0, 0, 580, 360, $f_width, $f_height);//返回布尔值
//清除输出
ob_clean();
header("content-type: image/png");
imagepng($bg);
//释放图片资源
imagedestroy($bg);
本作品采用《CC 协议》,转载必须注明作者和本文链接
算法是这么个算法;实际上每次请求都要这么合并的话,qps上来就很消耗服务器的cpu;正解还是先生成一个静态图比较好