程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> PHP綜合 >> 如何讓PHP同時支持GIF、png、JPEG

如何讓PHP同時支持GIF、png、JPEG

編輯:PHP綜合

如何讓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 -ql libjpeg-6b-10 查看,發現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-x.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. Make sure you shut down your
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.conf file and add:
   For PHP 4:  AddType application/x-httpd-php .PHP

You can choose any extension you wish here. .PHP is simply the one
we suggest. You can 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
  use a HUP or USR1 signal.)
---------------------------------------
   
終於成功了,你可以啟動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() &mdash; 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
……
絕對沒問題!!!!

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved