首页 技术 正文
技术 2022年11月16日
0 收藏 544 点赞 2,688 浏览 1163 个字

根据官方GD 库绘制图像文档样式

原基本样式

$width = 120;$height = 50;$img = @imagecreatetruecolor($width, $height) or die(‘Cannot Initialize new GD image stream’);;//新建一个GD图像资源$img_bgcolor = imagecolorallocate($img, mt_rand(157,255), mt_rand(157,255), mt_rand(157,255));//背景色$img_textcolor = imagecolorallocate($img, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));//字体颜色$img_rectangle = imagefilledrectangle($img,0,0,$width, $height,$img_bgcolor);//画一个矩形图像imagestring($img, 1, 5, 5, ‘A Simple Text String’, $img_textcolor);// 输出图像header(“Content-type:image/png”);imagepng($img);imagedestroy($img);//销毁图像  但在实际运用中会出现无法正常显示图像的问题:出现的原因可能有以下几种情况:  原因1:文件编码格式带有BOM 头,解决方法,用第3方编码工具,sublime 或 notepad++ 等把 文件格式保存为无BOM 的utf-8 格式  原因2:PHP缓冲区的问题,解决方法利用 ob_clean();清空缓冲区。 常用缓冲区函数 ob 函数参考:http://php.net/manual/zh/ref.outcontrol.php

ob_get_contents() – 返回输出缓冲区的内容

ob_flush() – 冲刷出(送出)输出缓冲区中的内容

ob_clean() – 清空(擦掉)输出缓冲区

ob_end_flush() – 冲刷出(送出)输出缓冲区内容并关闭缓冲

ob_end_clean() – 清空(擦除)缓冲区并关闭输出缓冲

flush() – 刷新输出缓冲

判断GD库是否安装

function_exists(‘imagecreate’) 通过判断扩展库提供的方法是否存在来判断get_extension_funcs() ,但不全面,不推荐该方式(因为有些扩展是没有提供函数的)

in_array(‘扩展名’, get_loaded_extensions()) 通过验证扩展是否在已加载的扩展中来判断是否安装(全面,但不简练)

extension_loade(‘扩展库名’) 通过判断扩展库是否加载来验证(全面,且不简练,推荐使用该方式来验证扩展是否安装加载)

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,086
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,561
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,410
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,183
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,820
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,903