安装GD库解决ThinkPHP 验证码Call to undefined function Think\imagecreate()出错

简介: 在php中imagecreate函数是一个图形处理函数,主要用于新建一个基于调色板的图像了,然后在这个基础上我们可以创建一些图形数字字符之类的,但这个函数需要GD库支持,如果没有开启GD库使用时会提示Call to undefined function imagecreate()错误。
在php中imagecreate函数是一个图形处理函数,主要用于新建一个基于调色板的图像了,然后在这个基础上我们可以创建一些图形数字字符之类的,但这个函数需要GD库支持,如果没有开启GD库使用时会提示Call to undefined function imagecreate()错误。

例,我在测试一个简单生成图形时实例

Example #1 新建一个新的 GD 图像流并输出图像

 代码如下 复制代码

<?php header("Content-type: image/png"); $im = @imagecreate(100, 50)     or die("Cannot Initialize new GD image stream"); $background_color = imagecolorallocate($im, 255, 255, 255); $text_color = imagecolorallocate($im, 233, 14, 91); imagestring($im, 1, 5, 5,  "A Simple Text String", $text_color); imagepng($im); imagedestroy($im); ?>

运行机制时提示

Fatal error: Call to undefined function imagecreate() .....

后面突然想起没打开gd库了

这一问题是:GD库没有正确安装或配置,解决方案:

在php.ini中找到 ;extension=php_gd2.dll 去掉前边的; 然后将php目录中的ext下的php_gd2.dll拷入c:/windows/system32和c:/windows目录下,重启IIS或者apache就OK了.

centos中gd库开启

具体操作只有2个命令如下: 运行在线安装带GD库的PHP的命令:

 代码如下 复制代码
yum -y install php-gd

重新启动apachce服务以使安装后的GD库生效

 代码如下 复制代码
/etc/rc.d/init.d/httpd restart(service httpd restart)

gd的安装路径

/etc/php.d/gd.ini                 <---这个是让php支持gd的哦,这个是CentOS的特色之一,不用把全部东西都写在php.ini这个文件里,只是需要把*.ini文件写在/etc/php.d/文件夹就可以了,系统会自动把这个目录下的*.ini读入php.ini /usr/lib/php/modules/gd.so   <----这个就是gd的文件啦

目录
相关文章
|
数据采集 自然语言处理 Devops
ToolLearning Eval:CodeFuse发布首个中文Function Call的大语言模型评测基准!🚀
CodeFuse发布了首个面向ToolLearning领域的中文评测基准ToolLearning-Eval,以帮助开发者跟踪ToolLearning领域大模型的进展,并了解各个ToolLearning领域大模型的优势与不足。ToolLearning-Eval按照Function Call流程进行划分,包含工具选择、工具调用、工具执行结果总结这三个过程,方便通用模型可以对各个过程进行评测分析。
942 0
|
8月前
|
前端开发 PHP
ThinkPHP 验证码扩展库的使用,以及多应用模式下,如何自定义验证码校验规则
本文介绍了在ThinkPHP框架中使用验证码扩展库的方法,包括安装验证码扩展库、在页面中使用验证码、自定义验证码配置以及校验验证码的步骤和代码示例。
ThinkPHP 验证码扩展库的使用,以及多应用模式下,如何自定义验证码校验规则
|
9月前
|
文字识别 Linux Swift
多图理解,更懂中文,支持function call的Phi-3.5来了!
微软继今年4月推出Phi-3系列小型语言模型后,又一鼓作气三连发布并开源其「小而美」系列 Phi-3.5模型!
|
9月前
|
关系型数据库 Linux PostgreSQL
【Azure 应用服务】Azure Function App Linux环境下的Python Function,安装 psycopg2 模块错误
【Azure 应用服务】Azure Function App Linux环境下的Python Function,安装 psycopg2 模块错误
|
9月前
【Azure Function】Function App和Powershell 集成问题, 如何安装PowerShell的依赖模块
【Azure Function】Function App和Powershell 集成问题, 如何安装PowerShell的依赖模块
Fatal error: Call to undefined function openssl_pkey_get_private()
Fatal error: Call to undefined function openssl_pkey_get_private()
119 0
|
Python
Python(二十九)pycharm连接调试器失败 Interrupted function call accept failed~
Pycharm在使用调试器模式时报错: Interrupted function call: accept failed
431 0
|
9月前
|
存储 JavaScript 前端开发
成功解决:Cannot read properties of undefined (reading ‘commit‘)
这篇文章提供了解决Vuex中"Cannot read properties of undefined (reading 'commit')"错误的两种方法:检查模板中的数据属性是否存在,以及确保在Vue实例中正确挂载了store对象。
成功解决:Cannot read properties of undefined (reading ‘commit‘)
|
9月前
|
定位技术 Apache
Echarts——Invalid geoJson format Cannot read property 'length' of undefined
Echarts——Invalid geoJson format Cannot read property 'length' of undefined
157 0
|
9月前
|
JavaScript
VUE——filemanager-webpack-plugin报错TypeError: Cannot read property 'isFile' of undefined
VUE——filemanager-webpack-plugin报错TypeError: Cannot read property 'isFile' of undefined
192 0

热门文章

最新文章