企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持知识库和私有化部署方案 广告
https://ihavenolimitations.xyz/a173512/php_note/1690618 ## **PHP函数生成二维码** ``` <?php //创建一个新图形 $image = imagecreatetruecolor(400,100); //分配颜色 $bgColor = imagecolorallocate($image,250,250,250); $black = imagecolorallocate($image,0,0,0); //填充背景 imagefill($image,0,0,$bgColor); //指定imagettftext()函数使用的字体 $font = "simhei.ttf"; //字义要输出的中文字符串 $string = "这是PNG图形asdasdasdasdasdasdas"; //对中文字符进行编码 // $string = iconv("GB2312","UTF-8",$string); // //使用imagettftext()函数输出文字 imagettftext($image,20,0,30,30,$black,$font,$string); //把PNG图形保存为文件(注意这里的区别)** imagepng($image,"pngfile.png"); //把PNG图形输出到浏览器(注意这里的区别)** header("Content-type: image/png"); imagepng($image); //释放资源 imagedestroy($image); ?> ``` 访问http://localhost/img.php 效果: ![](https://img.kancloud.cn/16/6f/166fa8a3eca6250b26efff51bd167b10_478x149.png) [二维码phpqrcode · PHP笔记 · 看云 (kancloud.cn)](https://ihavenolimitations.xyz/book/a173512/php_note/preview/%E4%BA%8C%E7%BB%B4%E7%A0%81phpqrcode.md)