<img src="<?php echo createNewPic($name,$sex,$fw);?>">
<?php
function createNewPic($names,$sexs,$fws)
{
//背景图片
$path_1 = ‘img/bg2.png‘;
//照片
$path_2= ‘img/1.png‘;
//创建图片对象
$image_1 = imagecreatefrompng($path_1);
$image_2 = imagecreatefrompng($path_2);
//合成图片
imagecopymerge($image_1, $image_2, 49, 111, 0, 0, imagesx($image_2), imagesy($image_2), 100);
//这是要插入到图片的文字
$name =$names;
$sex =$sexs;
$fw ="您本次志愿者服务时长为".$fws."小时";
//文件名
$filename="mlj";
//设置文字颜色
$black = imagecolorallocate($image_1, 41, 80, 49);
//写的文字用到的字体
$font = ‘img/msyh.ttf‘;
$font2= ‘img/msyhbd.ttf‘;
//在图片里插入文字$black
imagettftext($image_1, 25, 0, 270, 320, $black,$font, $name);
imagettftext($image_1, 14, 0, 380, 320, $black,$font, $sex);
imagettftext($image_1, 22, 0, 125, 670, $black,$font2, $fw);
//这是合成后的图片保存的路径
$upload_dir = "public/";
$pic=$upload_dir.$filename.‘‘.microtime().‘.png‘;
imagepng($image_1,$pic);
return $pic;
}
?>
原文:https://blog.51cto.com/14143040/2556087