标签

Honeymoon - Thomas Ng

归档

近期文章

php 图片添加文字并保存,生成奖状等

php 图片添加文字并保存,生成奖状等

代码

        ob_clean();
        header('Content-Type: image/png');
        $realname = "张  三";
        $schoolname = "100.50";

        $image = imagecreatefrompng(public_path().'/images/certificate.png');      //书模版图片文件的路径 必须是png格式的文件

        $red = imagecolorallocate($image,00,00,00); // 字体颜色
// imagettftext("Image", "Font Size", "Rotate Text", "Left Position","Top Position", "Font Color", "Font Name", "Text To Print");
//根据文本填写的位置不同
//"Left Position 和 Top Position 可以使用 getimagesize进行配合计算文字x和y轴坐标
        imagettftext($image, 60, 0, 650, 1545, $red, public_path().'/font/SimHei.ttf',$realname);
        imagettftext($image, 60, 0, 450, 1845, $red, public_path().'/font/SimHei.ttf', $schoolname);

        $filename = public_path().'/images/asdf.png';
        imagepng($image, $filename);

        imagedestroy($image);
        die();

certificate.png

R-C

SimHei.ttf

链接:https://pan.baidu.com/s/1pK548myzgWe_741Zp9pRew 提取码:1234

文件展示

微信图片_20240228182320

Buy me a cup of coffee 🙂

觉得对你有帮助,就给我打赏吧,谢谢!

微信赞赏码链接,点击跳转:

php 图片添加文字并保存,生成奖状等插图2
Tags:
Previous Article
Next Article