php多图片和文字合成最终图片

时间:2022-10-24 00:08:57
<?php
$id=$_GET['id'];
$conn=mysql_connect("localhost","root","root");
mysql_select_db("yx",$conn);
mysql_query("set names utf8");
$sql="select * from pigcms_lottery where id='$id'";
$result=mysql_query($sql);
$arr=mysql_fetch_assoc($result);
//echo $arr['fist'];
//echo $arr['second'];
//echo $arr['third'];
//echo $arr['four'];
//echo $arr['five'];
//echo $arr['six'];
function hc1($content1,$content2,$content3,$content4,$content5,$content7){
/*打开图片*/
//1.配置图片路径
$src = "http://localhost/tpl/Wap/default/common/css/guajiang/images/bb.png";
//2.获取图片信息
$info = getimagesize($src);
//3.通过编号获取图像类型
$type = image_type_to_extension($info[2],false);
//4.在内存中创建和图像类型一样的图像
$fun = "imagecreatefrom".$type;
//5.图片复制到内存
$image = $fun($src);
$background = imagecolorallocate($image, 255, 255, 255);
imagecolortransparent($image, $background);
//imagealphablending($image, false);
imagesavealpha($image, true);
/*操作图片*/
//1.设置字体的路径
$font = "msyh.ttf";
//2.填写水印内容
$size=15;
//$content1 = "";
//3.设置字体颜色和透明度
$color = imagecolorallocatealpha($image, 255, 255,255,0);
//4.写入文字
imagettftext($image, "$size", -45, 325, 80, $color, $font, $content1);
//$content2 = "";
//3.设置字体颜色和透明度
$color = imagecolorallocatealpha($image, 255, 255,255,0);
//4.写入文字
imagettftext($image, "$size", 90, 40, 250, $color, $font, $content2);
//$content3 = "";
//3.设置字体颜色和透明度
$color = imagecolorallocatealpha($image, 255, 255,255,0);
//4.写入文字
imagettftext($image,"$size", 130, 112,360, $color, $font, $content3);
//$content4 = "";
//3.设置字体颜色和透明度
$color = imagecolorallocatealpha($image, 255, 255,255,0);
//4.写入文字
imagettftext($image,"$size", 0, 160, 400, $color, $font, $content4);
//$content5 = "";
//3.设置字体颜色和透明度
$color = imagecolorallocatealpha($image, 255, 255,255,0);
//4.写入文字
imagettftext($image, "$size", 40, 310, 380, $color, $font, $content5);
$content6 = "谢谢参与";
//3.设置字体颜色和透明度
$color = imagecolorallocatealpha($image, 255, 255,255,0);
//4.写入文字
imagettftext($image, "$size", 88, 400, 265, $color, $font, $content6);
//$content7= "";
//3.设置字体颜色和透明度
$color = imagecolorallocatealpha($image, 255, 255,255,0);
//4.写入文字
imagettftext($image,"$size", 0, 185, 40, $color, $font, $content7);
$content8 = "谢谢参与";
//3.设置字体颜色和透明度
$color = imagecolorallocatealpha($image, 255, 255,255,0);
//4.写入文字
imagettftext($image, "$size", 50, 70, 120, $color, $font, $content8);
/*输出图片*/
//浏览器输出
header("Content-type:".$info['mime']);
$fun = "image".$type;
//$fun($image);
//保存图片
$fun($image,'bg_res.'.$type);
imagepng($image, "C:\\newbb3.png");
//imagejpeg($image, "C:\\newbb.jpg");
/*销毁图片*/
imagedestroy($image);
}
echo hc1($arr['six'],$arr['second'],$arr['third'],$arr['four'],$arr['five'],$arr['fist']);
function hc2($qCodePath,$img4,$img5,$img6,$img7,$img9){
$bigImgPath = 'C:\\newbb3.png';
$img3='http://localhost/tpl/Wap/default/common/css/guajiang/images/zlyc.png';
$img8='http://localhost/tpl/Wap/default/common/css/guajiang/images/jxnl.png';
$bigImg = imagecreatefromstring(file_get_contents($bigImgPath));
$qCodeImg = imagecreatefromstring(file_get_contents($qCodePath));
$qCodeImg3= imagecreatefromstring(file_get_contents($img3));
$qCodeImg4= imagecreatefromstring(file_get_contents($img4));
$qCodeImg5= imagecreatefromstring(file_get_contents($img5));
$qCodeImg6= imagecreatefromstring(file_get_contents($img6));
$qCodeImg7= imagecreatefromstring(file_get_contents($img7));
$qCodeImg8= imagecreatefromstring(file_get_contents($img8));
$qCodeImg9= imagecreatefromstring(file_get_contents($img9));
$qCodeWidth='60px';
$qCodeHight='60px';
list($qCodeWidth, $qCodeHight, $qCodeType) = getimagesize($qCodePath);
list($qCodeWidth3, $qCodeHight3, $qCodeType) = getimagesize($img3);
list($qCodeWidth4, $qCodeHight4, $qCodeType) = getimagesize($img4);
list($qCodeWidth5, $qCodeHight5, $qCodeType) = getimagesize($img5);
list($qCodeWidth6, $qCodeHight6, $qCodeType) = getimagesize($img6);
list($qCodeWidth7, $qCodeHight7, $qCodeType) = getimagesize($img7);
list($qCodeWidth8, $qCodeHight8, $qCodeType8) = getimagesize($img8);
list($qCodeWidth9, $qCodeHight9, $qCodeType9) = getimagesize($img9);
// imagecopymerge使用注解
imagecopymerge($bigImg, $qCodeImg, 190, 80, 0, 0, $qCodeWidth, $qCodeHight, 100);
imagecopymerge($bigImg, $qCodeImg3, 113, 95, 0, 0, $qCodeWidth3, $qCodeHight3, 100);
imagecopymerge($bigImg, $qCodeImg4, 70, 190, 0, 0, $qCodeWidth4, $qCodeHight4, 100);
imagecopymerge($bigImg, $qCodeImg5, 90, 280, 0, 0, $qCodeWidth5, $qCodeHight5, 100);
imagecopymerge($bigImg, $qCodeImg6, 173, 300, 0, 0, $qCodeWidth6, $qCodeHight6, 100);
imagecopymerge($bigImg, $qCodeImg7, 270, 290, 0, 0, $qCodeWidth7, $qCodeHight7, 100);
imagecopymerge($bigImg, $qCodeImg8, 300, 200, 0, 0, $qCodeWidth8, $qCodeHight8, 100);
imagecopymerge($bigImg, $qCodeImg9, 280, 120, 0, 0, $qCodeWidth9, $qCodeHight9, 100);
list($bigWidth, $bigHight, $bigType) = getimagesize($bigImgPath);
$background = imagecolorallocate($bigImg, 255, 255, 255);
imagecolortransparent($bigImg, $background);
imagesavealpha($bigImg, true);
switch ($bigType) {
case 1: //gif
header('Content-Type:image/gif');
imagegif($bigImg);
break;
case 2: //jpg
header('Content-Type:image/jpg');
imagejpeg($bigImg);
break;
case 3: //jpg
header('Content-Type:image/png');
imagepng($bigImg);
break;
default:
# code...
break;
}
imagepng($bigImg, "C:\\nbb.png");
imagedestroy($bigImg);
}
//echo hc2("http://localhost/tpl/Wap/default/common/css/guajiang/images/hwsh.png","http://localhost/tpl/Wap/default/common/css/guajiang/images/hwsh.png","http://localhost/tpl/Wap/default/common/css/guajiang/images/hwsh.png","http://localhost/tpl/Wap/default/common/css/guajiang/images/hwsh.png","http://localhost/tpl/Wap/default/common/css/guajiang/images/hwsh.png","http://localhost/tpl/Wap/default/common/css/guajiang/images/hwsh.png");
echo hc2($arr['bg1'],$arr['bg2'],$arr['bg4'],$arr['bg5'],$arr['bg6'],$arr['bg7']);
?>