Maison  >  Article  >  php教程  >  php Fatal error: Call to undefined function imagecreatefromjpeg()

php Fatal error: Call to undefined function imagecreatefromjpeg()

WBOY
WBOYoriginal
2016-05-26 08:20:261391parcourir

imagecreatefromjpeg函数是一个图像处理函数,但在使用中发现Fatal error: Call to undefined function imagecreatefromjpeg()错误了,下文小编整理了一些教程,大家一起来看看吧.

代码如下:

if(!imagecreatefromjpeg("./testimg.jpg")) 
{ 
    echo "imagecreatefromjpeg(testimg.jpg) failed!n)"; 
}   
else  
{ 
    echo "imagecreatefromjpeg(testimg.jpg) succn)"; 
}

如果你使用此函数提示php Fatal error: Call to undefined function imagecreatefromjpeg()

这个错误是因为没有安装gd 的jpeg,虽然你用phpinfo 查看有gd但 gd 不支持 jpeg,安装前我的phpinfo 如下:

gd 
GD Support enabled 
GD Version bundled (2.0.34 compatible) 
FreeType Support enabled 
FreeType Linkage with freetype 
FreeType Version 2.2.1 
GIF Read Support enabled 
GIF Create Support enabled 
PNG Support enabled 
libPNG Version 1.2.10 
WBMP Support enabled 
XBM Support enabled

显然gd 没有支持jpeg 的,下面要安装 gd中的 jpeg,代码如下:

1、找到php 源码目录

2、进入 ext/gd 目录

3、/usr/local/php/bin/phpize

4、./configure –with-php-config=/usr/local/php/bin/php-config –with-jpeg-dir –with-freetype-dir

5、make && make install

6、重启 httpd

安装后查看phpinfo

gd 
GD Support enabled 
GD Version bundled (2.0.34 compatible) 
FreeType Support enabled 
FreeType Linkage with freetype 
FreeType Version 2.2.1   
GIF Read Support enabled 
GIF Create Support enabled 
JPEG Support enabled 
libJPEG Version 6b 
PNG Support enabled 
libPNG Version 1.2.10 
WBMP Support enabled 
XBM Support enabled

很显然多了个 JPEG Support enabled

以windows下的php+apache:

首先,打开php.ini,找到"extension=php_gd.dll",然后去掉前面的";"注释,重启apache即可.

如果还出现此类问题,先检查php.ini的extension_dir值是哪个目录,在那个目录下检查有无php_gd.dll,没有的话请下载php_curl.dll,再把php目录中的libeay32.dll和ssleay32.dll拷到c:windowssystem32里面,重启apache,OK!


本文链接:

收藏随意^^请保留教程地址.

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn