PHP图片和文字合成函数刚刚出炉
public function createOnlineCourseCertsImgFront() { //照片 $path_2=ROOT_PATH . 'public/uploads/certsimg/12.png'; //背景图片 $path_1 = ROOT_PATH . 'public/uploads/certsimg/11.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 = '李天一'; $idnum = '00000001'; $validtime = '2020-10-31'; $sex='男'; $certtime='2020-05-26'; //文件名 $filename="temp"; //设置文字颜色 $black = imagecolorallocate($image_1, 0, 0, 0); //写的文字用到的字体 $font = ROOT_PATH . 'public/uploads/certsimg/simfang.ttf'; //在图片里插入文字$black imagettftext($image_1, 20, 0, 339, 130, $black,$font, $name); imagettftext($image_1, 20, 0, 555, 130, $black,$font, $sex); imagettftext($image_1, 20, 0, 339, 188, $black, $font, $idnum); imagettftext($image_1, 20, 0, 339, 243, $black, $font, $certtime); imagettftext($image_1, 20, 0, 339, 293, $black, $font, $validtime); //这是合成后的图片保存的路径 $upload_dir = "public/uploads/certsimg/"; imagepng($image_1, ROOT_PATH . $upload_dir . $filename . '.png'); $finalurl='uploads/certsimg/'.$filename . '.png'; return $finalurl; }
效果图如下