首頁  >  文章  >  後端開發  >  讓你的PHP同時支援GIF、png、JPEG

讓你的PHP同時支援GIF、png、JPEG

WBOY
WBOY原創
2016-07-29 08:34:221049瀏覽

讓你的PHP同時支援GIF、png、JPEG
在RedHat6.2按php的manual編譯安裝,發現只能處理GIF影像,無法處理JPEG影像。後來知道PHP處理影像,使用了GD庫,而GD庫開始時是支援GIF的,但由於GIF使用了有版權爭議的LZW演算法,會引起法律問題,於是從GD-1.6開始,GD庫不再支持GIF,改為支援更好的,無版權爭議的PNG。而我現在希望同時支援GIF,PNG和JPEG。
1、 Jpeg6b的安裝
RedHat6.2中已經有了RPM包,我們也就不需要去費勁編譯了。
  放入安裝盤
  mount /mnt/cdrom
  cd /mnt/cdrom/RedHat/RPMS
  rpm -ivh libjpeg*
安裝成功,用rpm-6l libjpeg查看,發現libjpeg.so.62.0.0被拷到/usr/lib目錄下。記住這目錄,等一下配php時要用。
2、 GD-1.8.3的安裝
取得GD原始碼的位址為:
http://www.boutell.com/gd/
當然可以自己編譯,但它不支持jpeg,要打補丁。
取得補丁原始碼的位址為:
http://www.webofsin.com/gd-1.8.3-gif.patch
接下來………………麻煩死了……勸你還是不要自己編譯了! !
有現成的東西為何不用呢?已經有人打好補丁編譯好了,做成RPM。
可以在:
http://rpms.arvin.dk/rh7-backports/gd/
http://rpms.arvin.dk/gd-with_gif/
得到。世上竟然有這麼好的人? ;-真是令人感動! ! !
下載了幾個gd-with_gif*.rpm後直接 rpm -ivh gd-with_gif* 安裝。
用rpm -ql gd-with_gif-1.8.3-7 看
發現libgd.so.1.8.3 放到了/usr/gd-with_gif/lib 下
記住此目錄,配php時也要用。
3、 PHP的安裝與設定
鑑於曾聽說php4.0不支援jpeg(不知記錯沒),我建議還是用php的最新版。
下面的,大家應該熟悉得不能再熟悉了吧?
所以我把php的manual抄下來:
---------------------------------
1. gunzip apache_1.3.x.tar.gz
2. tar xvf apache_1.3.x.tar
3. gunzip php-x.x.x.tar.gz
4. tar xvf php-tarx.x.x.tar.
5. cd apache_1.3.x
6. ./configure --prefix=/www
7. cd ../php-x.x.x
8. 這裡是關鍵! ! !
  ./configure --with-mysql --with-apache=../apache_1.3.x --enable-track-vars --with-jpeg-dir=/usr/lib --with-gd= /usr/gd-with_gif/lib
  當然你也可以加上自己的選項,此不贅述。
9. make
10. make install
11. cd ../apache_1.3.x
12. for PHP 4: ./configure --activate-module=src/modules/php4 /libphp4.a
13. make
14. make install
Instead of this step you may prefer to simply copy the httpd binary
overtop of your existing binary. > server first though.
15. cd ../php-x.x.x
16. for PHP 4: cp php.ini-dist /usr/local/lib/php.ini
You can edit your . ini file to set PHP options. If
you prefer this file in another location, use
--with-config-file-path=/path in step 8.
17. Edit your httpd.conf or srm。 even include .html .
18. Use your normal procedure for starting the Apache server. (You must
  stop and restart the server, not just cause the server to reload by
US.R1 a H. )
---------------------------------------
終於成功了,你可以啟動apache用phpinfo()試一試,發現gd那裡:
----------------------
    gd
GD Support enabled
GD Version 1.6.2 or higher
GIF Support enabled
PNG Support enabled
JPG Support enabled
WBMP Support enabled
---- ----------
^_^哈哈哈哈哈哈哈哈哈^_^
你現在可以用到所有的php圖形函數了:
ImageCreateFromGIF() — Create a new image from file or URL
ImageCreateFromJPEG() — Create a new image from file or URL
ImageCreateFromPNG() — Create a new image from file or URL

絕對沒問題! ! ! !
以上就介紹了 讓你的PHP同時支援GIF、png、JPEG,包含了方面的內容,希望對PHP教學有興趣的朋友有幫助。


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn