Call to undefined function imagecreatefromjpeg() 让GD支持JPEG格式的图片扩展

 

安装扩展支持jpeg格式:

 

 

第一步:首先下载文件:
版本v8:
wget http://www.ijg.org/files/jpegsrc.v8b.tar.gz
版本v9:
wget http://www.ijg.org/files/jpegsrc.v9c.tar.gz

把jpeg安装到home目录:

 



./configure --prefix=/home/jpeg --enable-shared --enable-static 
make && make install

第二步:安装到配置文件中
1、找到php 源码目录 
cd /home/ubuntu/downphp/php-7.0.0

2、进入 ext/gd 目录
cd /home/ubuntu/downphp/php-7.0.0/ext/gd

3、执行命令:/home/php/bin/phpize
[root@daokr gd]#/home/php/bin/phpize
Configuring for:
PHP Api Version:         20151012
Zend Module Api No:      20151012
Zend Extension Api No:   320151012

4、注意 with-freetype-dir 路径必须加载否则报错
./configure --with-php-config=/home/php/bin/php-config --with-jpeg-dir=/home/jpeg --with-freetype-dir=/usr/local/include/freetype2

5、make && make install
6、重启 httpd

如果上面的步骤解决不了那就重新安装php吧:


记得把
--with-jpeg-dir=/home/jpeg 加上

 重新安装phpconfig

./configure --prefix=/home/php --with-config-file-path=/home/php/etc --with-fpm-user=ubuntu --with-fpm-group=ubuntu --with-pdo-mysql --with-openssl --with-pear --with-mhash --with-xmlrpc --with-zlib --with-mcrypt --with-curl --with-jpeg-dir=/home/jpeg --with-gd --with-freetype-dir=/usr/local/include/freetype2 --without-sqlite3 --without-pdo-sqlite --disable-rpath --without-pear --enable-fpm --enable-maintainer-zts --enable-pcntl --with-tsrm-pthreads --enable-mbstring --enable-mbregex --enable-bcmath --enable-zip --enable-sockets --enable-soap --enable-gd-native-ttf --enable-xml --enable-inline-optimization --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd

 liconv close 错误解决:vim MakeFile

EXTRA_LIBS = -lcrypt -lz -lresolv -lcrypt -lmcrypt -lltdl -lpng -lz -ljpeg -lcurl -lz -lrt -lm -ldl -lnsl -lxml2 -lssl -lcrypto -lcurl -lxml2 -lssl -lcrypto -lfreetype -lxml2 -lxml2 -lcrypt -lxml2 -lxml2 -lxml2 -lxml2 -lssl -lcrypto -lcrypt -liconv

 

 

这个版本不能用imagecreatefromjpeg:

Warning: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable

为啥呢;百度了半天没解决最后还是重新编译php安装了。

 

最终还是重新编译了PHP配置

1 ./configure --prefix=/home/php --with-config-file-path=/home/php/etc --with-fpm-user=ubuntu --with-fpm-group=ubuntu --with-pdo-mysql --with-openssl --with-pear --with-mhash --with-xmlrpc --with-zlib --with-mcrypt --with-curl --with-jpeg-dir --with-png-dir --with-gd --with-freetype-dir=/usr/local/include/freetype2 --without-sqlite3 --without-pdo-sqlite --disable-rpath --without-pear --enable-fpm --enable-maintainer-zts --enable-pcntl --with-tsrm-pthreads --enable-mbstring --enable-mbregex --enable-bcmath --enable-zip --enable-sockets --enable-soap --enable-gd-native-ttf --enable-xml --enable-inline-optimization --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-ftp --with-gettext --enable-opcache

 

 

$f = 'uploads/face/010/00/00/2296f8b53a3324e528ff37cba61cb14f_240_240.jpg';
var_dump(getImageSize($f));
$a = imagecreatefromjpeg($f);
var_dump($a);die;

 

 成功输出:

 

 

 

posted @ 2018-10-22 22:35  王小麦  阅读(...)  评论(...编辑  收藏