- 最近项目中遇到一个业务场景,需要生成条码和二维码并以base64文件输出
- 一般使用imagejpeg函数只能将图片输出到文件或者浏览器,因此需要借助缓存
//1.创建图片 $img=imagecreatetruecolor(500,400); //2.准备颜色 $black=imagecolorallocate($img,0,0,0); //3.在画布上画图像或文字 imagefill($img,0,0,$black); ob_start(); //开启缓存 imagejpeg($img); //将图片输出到缓存 $imageCode = ob_get_contents(); //读取缓存内容 $baseImg = base64_encode($imageCode); ob_end_clean(); //关闭缓存
php GD库画图并保存到变量
最新推荐文章于 2021-03-30 17:18:01 发布