博主信息
R࿆ebirth༢局外人
博文
12
粉丝
0
评论
0
访问量
2332
积分:0
P豆:24

php遇到错误Call to undefined function ImageCreate()解决方法

2021年10月03日 12:47:36阅读数:273博客 / R࿆ebirth༢局外人

常规Ubuntu与windows
编译make安装方法
phpize方法
centos安装GD库
在使用php处理一些图像时,有时会出现诸如这样的错误:Call to undefined function imagecreate()

这是由于没有安装或是没有开启php的gd库导致的问题。

常规Ubuntu与windows
解决方案:

一、在linux系统(这里用的是Ubuntu系统)下

首先在终端输入下列命令:

sudo apt-get install php5-gd

这样就已经安装完php的gd库了。如果使用的是apache服务器,这时还需重启下服务器:

sudo service apache2 restart

如果是nginx则可用可不用。

二、在windows系统下

打开php安装目录下的php.ini配置文件,找到这一行:

;extension=php_gd2.dll

将这一行前面的;号去掉,然后保存。这样已经开启了gd扩展库。

最后重启下服务器就行了。

编译make安装方法
在编译配置扩展的时候就没加上gd的同学可以参考下面的方法

找到安装php的目录下,重新配置扩展

make clean
./configure —prefix=/png/php/5.6.40 —enable-fpm —with-apxs2=/usr/bin/apxs2 —enable-maintainer-zts -with-mysqli —with-pdo-mysql —with-pdo-sqlite —with-gd
make
make test
make install

./configure —with-gd有了就行,其他的扩展看需求

vim打开php.ini

搜索

vim命令关键字搜索: (1) 点ESC (2)/“关键字”

/extension=php_gd2.dll

找到这行去掉前面的分号“;”

phpize方法
原因:未安装php的gd库,主要处理图片的库

解决方法:

在已经安装php的情况先,需要对PHP进行扩展,加入gd库

1:进入到php源码里面的gd目录下

cd /usr/src/php-5.5.38/ext/gd/

2:执行phpize (命令在php/bin/目录下)

phpize

3:编译安装

./configure —with-php-config=/usr/local/php5/bin/php-config —with-png-dir —with-freetype-dir —with-jpeg-dir —with-gd
make
make install

会报错,执行下面命令:

yum install libpng
yum install libpng-devel
yum install freetype-devel

此时安装完成后会生成一个gd.so的文件,记住这个路径

ls /usr/local/php5/lib/php/extensions/no-debug-non-zts-20121212/
curl.so gd.so opcache.so pcntl.so pdo_mysql.so

4:修改php的配置文件php.ini将gd.so的路径加入进去,如下加入到最后面就行

vim /usr/local/php5/php.ini
[root@slb03 ~]# tail -1 /usr/local/php5/php.ini
extension=/usr/local/php5/lib/php/extensions/no-debug-non-zts-20121212/gd.so

5:重启apache服务

/etc/init.d/httpd restart

centos安装GD库
采用phpize的方式安装,也不成功

提示Cannot find config.m4.
[root@hotdata gd]# php -i | grep -i —color gd
PWD => /usr/include/php/ext/gd
_SERVER[“PWD”] => /usr/include/php/ext/gd

  1. [root@hotdata gd]# yum -y install m4
  2. Loaded plugins: security
  3. Setting up Install Process
  4. Package m4-1.4.13-5.el6.x86_64 already installed and latest version
  5. Nothing to do
  6. [root@hotdata gd]# yum -y install autoconf
  7. Loaded plugins: security
  8. Setting up Install Process
  9. Package autoconf-2.63-5.1.el6.noarch already installed and latest version
  10. Nothing to do
  11. [root@hotdata gd]# /usr/bin/phpize
  12. Cannot find config.m4.
  13. Make sure that you run '/usr/bin/phpize' in the top level source directory of the module
  14. 直接使用yum命令安装不成功,错误信息如下:

主要提示信息为需要安装依赖包,可是我已经安装了

  1. # yum install gd gd-devel php-gd
  2. Loaded plugins: security
  3. Setting up Install Process
  4. Package gd-2.0.35-11.el6.x86_64 already installed and latest version
  5. Resolving Dependencies
  6. --> Running transaction check
  7. ---> Package gd-devel.x86_64 0:2.0.35-11.el6 will be installed
  8. --> Processing Dependency: libpng-devel for package: gd-devel-2.0.35-11.el6.x86_64
  9. --> Processing Dependency: libjpeg-devel for package: gd-devel-2.0.35-11.el6.x86_64
  10. --> Processing Dependency: libXpm-devel for package: gd-devel-2.0.35-11.el6.x86_64
  11. --> Processing Dependency: libX11-devel for package: gd-devel-2.0.35-11.el6.x86_64
  12. --> Processing Dependency: freetype-devel for package: gd-devel-2.0.35-11.el6.x86_64
  13. --> Processing Dependency: fontconfig-devel for package: gd-devel-2.0.35-11.el6.x86_64
  14. ---> Package php-gd.x86_64 0:5.4.45-56.el6.art will be installed
  15. --> Processing Dependency: php-common(x86-64) = 5.4.45-56.el6.art for package: php-gd-5.4.45-56.el6.art.x86_64
  16. --> Processing Dependency: libt1.so.5()(64bit) for package: php-gd-5.4.45-56.el6.art.x86_64
  17. --> Running transaction check
  18. ---> Package fontconfig-devel.x86_64 0:2.8.0-5.el6 will be installed
  19. ---> Package freetype-devel.x86_64 0:2.3.11-17.el6 will be installed
  20. --> Processing Dependency: freetype = 2.3.11-17.el6 for package: freetype-devel-2.3.11-17.el6.x86_64
  21. ---> Package libX11-devel.x86_64 0:1.6.4-3.el6 will be installed
  22. --> Processing Dependency: libX11 = 1.6.4-3.el6 for package: libX11-devel-1.6.4-3.el6.x86_64
  23. --> Processing Dependency: pkgconfig(xcb) >= 1.11.1 for package: libX11-devel-1.6.4-3.el6.x86_64
  24. --> Processing Dependency: pkgconfig(xproto) for package: libX11-devel-1.6.4-3.el6.x86_64
  25. --> Processing Dependency: pkgconfig(xcb) for package: libX11-devel-1.6.4-3.el6.x86_64
  26. --> Processing Dependency: pkgconfig(kbproto) for package: libX11-devel-1.6.4-3.el6.x86_64
  27. ---> Package libXpm-devel.x86_64 0:3.5.10-2.el6 will be installed
  28. --> Processing Dependency: libXt.so.6()(64bit) for package: libXpm-devel-3.5.10-2.el6.x86_64
  29. ---> Package libjpeg-turbo-devel.x86_64 0:1.2.1-3.el6_5 will be installed
  30. ---> Package libpng-devel.x86_64 2:1.2.49-2.el6_7 will be installed
  31. ---> Package php-gd.x86_64 0:5.4.45-56.el6.art will be installed
  32. --> Processing Dependency: php-common(x86-64) = 5.4.45-56.el6.art for package: php-gd-5.4.45-56.el6.art.x86_64
  33. ---> Package t1lib.x86_64 0:5.1.2-6.el6_2.1 will be installed
  34. --> Running transaction check
  35. ---> Package freetype.x86_64 0:2.3.11-15.el6_6.1 will be updated
  36. ---> Package freetype.x86_64 0:2.3.11-17.el6 will be an update
  37. ---> Package libX11.x86_64 0:1.6.0-6.el6 will be updated
  38. ---> Package libX11.x86_64 0:1.6.4-3.el6 will be an update
  39. --> Processing Dependency: libX11-common = 1.6.4-3.el6 for package: libX11-1.6.4-3.el6.x86_64
  40. ---> Package libXt.x86_64 0:1.1.4-6.1.el6 will be installed
  41. ---> Package libxcb-devel.x86_64 0:1.12-4.el6 will be installed
  42. --> Processing Dependency: libxcb = 1.12-4.el6 for package: libxcb-devel-1.12-4.el6.x86_64
  43. --> Processing Dependency: pkgconfig(xau) >= 0.99.2 for package: libxcb-devel-1.12-4.el6.x86_64
  44. --> Processing Dependency: libxcb-xkb.so.1()(64bit) for package: libxcb-devel-1.12-4.el6.x86_64
  45. --> Processing Dependency: libxcb-xinput.so.0()(64bit) for package: libxcb-devel-1.12-4.el6.x86_64
  46. --> Processing Dependency: libxcb-sync.so.1()(64bit) for package: libxcb-devel-1.12-4.el6.x86_64
  47. --> Processing Dependency: libxcb-present.so.0()(64bit) for package: libxcb-devel-1.12-4.el6.x86_64
  48. --> Processing Dependency: libxcb-dri3.so.0()(64bit) for package: libxcb-devel-1.12-4.el6.x86_64
  49. ---> Package php-gd.x86_64 0:5.4.45-56.el6.art will be installed
  50. --> Processing Dependency: php-common(x86-64) = 5.4.45-56.el6.art for package: php-gd-5.4.45-56.el6.art.x86_64
  51. ---> Package xorg-x11-proto-devel.noarch 0:7.7-14.el6 will be installed
  52. --> Running transaction check
  53. ---> Package libX11-common.noarch 0:1.6.0-6.el6 will be updated
  54. ---> Package libX11-common.noarch 0:1.6.4-3.el6 will be an update
  55. ---> Package libXau-devel.x86_64 0:1.0.6-4.el6 will be installed
  56. ---> Package libxcb.x86_64 0:1.9.1-3.el6 will be updated
  57. ---> Package libxcb.x86_64 0:1.12-4.el6 will be an update
  58. ---> Package php-gd.x86_64 0:5.4.45-56.el6.art will be installed
  59. --> Processing Dependency: php-common(x86-64) = 5.4.45-56.el6.art for package: php-gd-5.4.45-56.el6.art.x86_64
  60. --> Finished Dependency Resolution
  61. Error: Package: php-gd-5.4.45-56.el6.art.x86_64 (atomic)
  62. Requires: php-common(x86-64) = 5.4.45-56.el6.art
  63. Installed: php-common-5.6.16-1.el6.remi.x86_64 (@remi-php56)
  64. php-common(x86-64) = 5.6.16-1.el6.remi
  65. Available: php-common-5.3.3-49.el6.x86_64 (base)
  66. php-common(x86-64) = 5.3.3-49.el6
  67. Available: php-common-5.4.45-54.el6.art.x86_64 (atomic)
  68. php-common(x86-64) = 5.4.45-54.el6.art
  69. Available: php-common-5.4.45-56.el6.art.x86_64 (atomic)
  70. php-common(x86-64) = 5.4.45-56.el6.art
  71. Available: php55w-common-5.5.38-1.w6.x86_64 (webtatic)
  72. php-common(x86-64) = 5.5.38-1.w6
  73. Available: php56w-common-5.6.40-1.w6.x86_64 (webtatic)
  74. php-common(x86-64) = 5.6.40-1.w6
  75. Available: php70w-common-7.0.33-1.w6.x86_64 (webtatic)
  76. php-common(x86-64) = 7.0.33-1.w6
  77. Available: php71w-common-7.1.26-1.w6.x86_64 (webtatic)
  78. php-common(x86-64) = 7.1.26-1.w6
  79. Available: php71w-common-7.1.27-1.w6.x86_64 (webtatic)
  80. php-common(x86-64) = 7.1.27-1.w6
  81. Available: php71w-common-7.1.28-1.w6.x86_64 (webtatic)
  82. php-common(x86-64) = 7.1.28-1.w6
  83. Available: php71w-common-7.1.29-1.w6.x86_64 (webtatic)
  84. php-common(x86-64) = 7.1.29-1.w6
  85. You could try using --skip-broken to work around the problem
  86. You could try running: rpm -Va --nofiles --nodigest
  87. 最后采用这种方式安装成功了

版权申明:本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!

全部评论

文明上网理性发言,请遵守新闻评论服务协议

条评论
  • ​下面由thinkphp教程栏目给大家介绍tp5Call to a member function toArray() on array的报,希望对需要的朋友有所帮助!