php 证书图片生成
时间 11 : 49 , Sep 28,2020
网上找底图,然后把文字和公章合成到一起,代码如下
//生成证书图片 cate 1为入会证书 2为资质证书
function createImg($cate=1,$word=""){
$img=[
"1"=>ROOT_PATH."public/static/moban/certificate1.png", //证书模板
"2"=>ROOT_PATH."public/static/moban/certificate2.png", //证书模板
];
$dests = imagecreatetruecolor(1024,724);
$src_im = imagecreatefrompng($img[$cate]);
imagesavealpha($dests,true);
imagealphablending($dests,false);
imagecopy($dests,$src_im,0,0,0,0,1024,724);
imagedestroy($src_im);
imagealphablending($dests,true);
$font_file = ROOT_PATH.'public/static/font/simhei.ttf'; //字体文件
$text_color = imagecolorallocate($dests,0,0,0); //字体颜色
$enterprise_name="合肥测试科技信息有限公司"; //公司名称
imagefttext($dests, 28, 0, 205, 345, $text_color, $font_file, $enterprise_name);
$certificate_no="AF123456"; //证书编号
imagefttext($dests, 28, 0, 505, 475, $text_color, $font_file, "证书编号:".$certificate_no);
$certificate_update_time="2020年09月28日"; //证书颁发日期
imagefttext($dests, 28, 0, 525, 545, $text_color, $font_file, $certificate_update_time);
$member_type="副理事长单位";
imagefttext($dests, 28, 0, 205, 385, $text_color, $font_file, $member_type);
//公章
$seal=ROOT_PATH."public/static/moban/seal.png";
$seal_im = imagecreatefrompng($seal);
imagesavealpha($seal_im,true);
imagealphablending($seal_im,false);
imagecopy($dests,$seal_im,555,405,0,0,308,310);
$dir_name =date('Ymd'); //图片存放路径/uploads/headimg'
$name=$certificate_no.'.png';
$file=ROOT_PATH."public/uploads/certificate/".$dir_name."/".$name;
if (!file_exists(ROOT_PATH."public/uploads/certificate/".$dir_name)) { // 查看文件夹是否存在
mkdir(ROOT_PATH."public/uploads/certificate/".$dir_name, 0777, true);
}
imagedestroy($seal_im);
imagesavealpha($dests,true);
imagealphablending($dests,false);
imagepng($dests,$file);
return "/uploads/certificate/".$dir_name."/".$name;
}合出来的图片如下

