//生成证书图片
public function create_pic($name = '',$create_time)
{
if(!$name){
$name = '测试';
}
$root = $_SERVER['DOCUMENT_ROOT'];//获取项目根据目录,存储图片使用
$dst_path = $root . '/uploads/cretpic.jpg';
//创建图片的实例
$dst = imagecreatefromstring(file_get_contents($dst_path));
//添加文字需要字体文件
$font = $root.'/uploads/simkai.ttf';//字体路径,自提文件,没有的下载一个就行
$black = imagecolorallocate($dst, 0, 0, 0);//字体颜色
//这个函数调整文字水印的位置,颜色等,具体可以查这个函数的使用
$imageArr = imagefttext($dst, 70, 0, 740, 1680, $black, $font, $name);//文字水印
if($create_time){
$year = date('Y',$create_time).'年';
$month = date('m',$create_time) .'月';
$day = date('d',$create_time) . '日';
}else{
$year = date('Y',time()).'年';
$month = date('m',time()) .'月';
$day = date('d',time()) . '日';
}
$imageArr = imagefttext($dst, 70, 0, 1440, 2980, $black, $font, $year);//水印年
$imageArr = imagefttext($dst, 70, 0, 1720, 2980, $black, $font, $month);//水印月
$imageArr = imagefttext($dst, 70, 0, 1910, 2980, $black, $font, $day);//水印日
//输出图片
list($dst_w, $dst_h, $dst_type) = getimagesize($dst_path);
switch ($dst_type) {
case 1://GIF
header('Content-Type: image/gif');
imagegif($dst);
break;
case 2://JPG
header('Content-Type: image/jpeg');
$filename = '/cert/'.time().rand(10000,90000).'.png';
$file_path = $root.$filename;
imagepng($dst, $file_path);//输入图片
break;
case 3://PNG
header('Content-Type: image/png');
imagepng($dst);
break;
default:
break;
}
imagedestroy($dst);
return $filename; //返回图片路径
php图片上打水印,文字
最新推荐文章于 2024-05-13 11:09:46 发布