Home » Code » PHP » PHP安装——启用了GD,却用不了jpeg的相关函数?

PHP安装——启用了GD,却用不了jpeg的相关函数?

最近编译安装PHP,编译参数明明写了–with-gd,phpinfo()查看也看到“GD Support enabled”。但实际使用时却报Call to undefined function imagecreatefromjpeg(),顿时茫然。一阵搜索,看到这么个说法:

If imagecreatefromjpeg() fails with “PHP Fatal error: Call to undefined function: imagecreatefromjpeg()”, it does NOT necessarily mean that you don’t have GD installed.

If phpinfo() shows GD, but not JPEG support, then that’s the problem. You would think that –with-gd would do the right thing since it does check for the existance of libjpeg (and finds it) and add that feature to GD, but it doesn’t in v4.4.4 at least on RHEL v2.1, RHEL v3, CentOS v2.1 or CentOS v4.3.

On those platforms, it’s *important* that –with-jpeg-dir be *before* –with-gd. If it’s not, GD won’t build with jpeg support as if –with-jpeg-dir had never been specified…

意思就是,别以为写了–with-gd就一切帮你搞定,这样子jpeg是不会帮你启用的(为啥?jpeg不是使用最广泛的么?为啥不默认帮搞定?)。实际上,phpinfo()上的GD信息是这样子的:

显然的看到PNG Support,却没有JPEG Support。打印gd_info()的结果能明确看到jpeg_support => false。正确的方式是还得加一句–with-jpeg-dir(前提是安装了jpeg相关的库,不是默认安装估计还得指定具体路径),坑!

这时候只有重新编译PHP,实在太麻烦,干脆使用imagick。这时候要注意,imagick只是PHP的一个扩展,实际它是调用ImageMagick的API来工作,因此要先安装ImageMagick。详细可查看参考链接。

参考链接:
http://blog.csdn.net/json_ligege/article/details/61914166
http://blog.sina.com.cn/s/blog_6718a8f40102vyzv.html
http://lisapig.blog.163.com/blog/static/17221546201511111534575/

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Time limit is exhausted. Please reload CAPTCHA.