动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
  
   PHP → 阅读文章

 让你的PHP同时支持GIF、png、JPEG

作者来源: 
阅读 1184 人次 , 2006-3-29 4:10:00 


在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() — 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的XML分析函数
· 下一篇:一种高效的分页机制
· 一个模仿oso的论坛程序(之一)
· 用IE远程创建Mysql数据库的简易程序
· dateadd(),datediff()两个函数的例程
· PHP脚本的8个技巧(7)
· php做饼图的函数


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077