主页 思维拓展 两个图片合并函数,常用于二维码
admin
发表于2018-01-05 16:22:25    只看楼主
楼主
头衔:  精益求精
注册时间: 2012-10-07
用户组: 日常管理组
发帖数:  485
金币数:  185
短消息
 function createPromotion($data){
	$bigImgPath = $data['bigImgPath'];
	$qCodePath = $data['qCodePath'];
	$filename = $data['filename'];
	$left = isset($data['left'])?$data['left']:194;
	$top = isset($data['top'])?$data['top']:590;
	$bigImg = imagecreatefromstring(file_get_contents($bigImgPath));
	$qCodeImg = imagecreatefromstring(file_get_contents($qCodePath));
	list($qCodeWidth, $qCodeHight, $qCodeType) = getimagesize($qCodePath);
	if($data['percent'] > 0) {
		$qCodeWidthNew = $qCodeWidth * $data['percent'];
		$qCodeHightNew = $qCodeHight * $data['percent'];
		$qCodeImgNew = imagecreatetruecolor($qCodeWidthNew, $qCodeHightNew);  
		imagecopyresampled($qCodeImgNew, $qCodeImg, 0, 0, 0, 0, $qCodeWidthNew, $qCodeHightNew, $qCodeWidth, $qCodeHight);
		imagecopymerge($bigImg, $qCodeImgNew, $left, $top, 0, 0, $qCodeWidthNew, $qCodeHightNew, 100);
	}else{
		imagecopymerge($bigImg, $qCodeImg, $left, $top, 0, 0, $qCodeWidth, $qCodeHight, 100);
	}
	list($bigWidth, $bigHight, $bigType) = getimagesize($bigImgPath);
	switch ($bigType) {
		case 1: //gif
			header('Content-Type:image/gif');
			imagegif($bigImg,$filename);
			break;
		case 2: //jpg
			header('Content-Type:image/jpg');
			imagejpeg($bigImg,$filename);
			break;
		case 3: //jpg
			header('Content-Type:image/png');
			imagepng($bigImg,$filename);
			break;
		default:
			# code...
			break;
	}
	imagedestroy($bigImg);
	imagedestroy($qCodeImg);
	imagedestroy($qCodeImgNew);
}
引用  把握生命里的每一分钟,没有人能随随便便成功~^_^

回复人
回复内容

Powered BY YouYaX
个人自主开发论坛,从2010年10月份开发至今!

操作管理