Home > php教程 > php手册 > body text

php Fatal error: Call to undefined function imagecreatefromjpeg()

WBOY
Release: 2016-05-26 08:20:26
Original
1389 people have browsed it

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

代码如下:

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

如果你使用此函数提示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
Copy after login

显然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
Copy after login

很显然多了个 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!


本文链接:

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!