配置PHP使之能同时支持GIF和JPEG_PHP
问题:安装蓝点Linux 2.0后,进行PHP编程,发现只能处理GIF图像,不能处理JPEG图像。后来知道PHP处理图像,使用了GD库,而GD库开始时是支持GIF的,但由于GIF使用了有版权争议的LZW算法,会引起法律问题,于是从GD-1.6开始,GD库不再支持GIF,改为支持更好的,无版权争议的PNG。而我现在希望同时支持GIF,PNG和JPEG。
经过尝试,我成功地做到了这一点。下面介绍具体做法。我的配置为:蓝点Linux 2.0,Kernel-2.2.16,MySQL-3.23.10alpha,Apache-1.3.12, PHP-4.0.1pl2,gd-1.8.3,Jpeg6b。
我将按照由底向上的顺序介绍,即Jpeg->GD->PHP->Apache。
0、 当前状态查看
安装蓝点Linux 2.0后,Kernel,MySQL,Apache未做任何改变,看看当前状态如何。
创建一PHP文件,名为info.php,放于Apahce的文档目录下(/etc/httpd/html),其内容如下:
phpinfo(); ?>
文件就只有1行。用浏览器打开该文件URL(我的hostname为zhangzh):
http://zhangzh/info.php
如果Apache/PHP正常运行的话,页面中将会列出PHP版本,Apache版本,以及其他各种有用的信息。我关心的是GD库部分,看看它是否支持GIF、JPEG,结果发现支持GIF而不支持JPEG。
1、 Jpeg6b的安装和配置
Jpeg的主要文件有jpeglib.h, libjpeg.a, libjpeg.so等。首先检查系统中安装了没有,到/usr/include目录下看有无jpeglib.h,到/usr/lib目录下看有无libjpeg.a和libjpeg.so。我的系统中没有,因而要安装。
获取Jpeg源码的地址为:
ftp://ftp.uu.net/graphics/jpeg/
取得的文件为jpegsrc.v6b.tar.gz,放于/usr/src目录下。
进入/usr/src目录中,开始安装过程。
进入/usr/src:
cd /usr/src
解开压缩文件:
tar xzvf jpegsrc.v6b.tar.gz
命令完成后多了一个子目录jpeg-6b,Jpeg的源码文件就在其中。
进入该子目录:
cd jpeg-6b
该目录中的install.doc文件详细介绍了如何安装Jpeg,照章行事即可。
配置生成Makefile文件:
./configure
命令完成后该目录下多了个Makefile文件。Makefile文件是许多软件编译、安装的配置和过程控制文件,十分重要,应该学会看懂它的内容。
开始编译:
make
命令完成后该目录下多了许多文件,其中重要的是libjpeg.a和libjpeg.so。
安装:
make install
命令完成后,jpeglib.h被拷到/usr/local/include目录下,libjpeg.a和libjpeg.so被拷到/usr/local/lib目录下。
2、 GD-1.8.3的安装和配置
GD的主要文件有gd.h, libgd.a等。
获取GD源码的地址为:
http://www.boutell.com/gd/
取得的文件为gd-1.8.3.tar.gz,放于/usr/src目录下。
已知道该版本的GD不支持GIF,但想来象我一样希望GD同时支持GIF和JPEG的人不少,于是有人做了个补丁,把对GIF的支持加回去了。看起来这是个英国人吧,他的Email地址为adam@elysium.ltd.uk。
获取补丁源码的地址为:
http://www.webofsin.com/gd-1.8.3-gif.patch
取得的文件为gd-1.8.3-gif.patch,放于/usr/src目录下。
进入/usr/src:
cd /usr/src
解开压缩文件:
tar xzvf gd-1.8.3.tar.gz
命令完成后多了一个子目录gd-1.8.3,GD的源码文件就在其中。
给源码打补丁:
patch -p0
进入该子目录:
cd gd-1.8.3
缺省情况下,GD库编译时并不加入JPEG支持,得修改Makefile文件。
修改Makefile文件,使得:
CFLAGS=-O -DHAVE_XPM -DHAVE_JPEG -DHAVE_LIBTTF
LIBS=-lm -lgd -lpng -lz -ljpeg -lttf -lXpm -lX11
此后,编译并安装:
make
make install
命令完成后,gd.h被拷到/usr/local/include目录下,libgd.a被拷到/usr/local/lib目录下。
3、 PHP-4.0.1pl2的安装和配置
PHP的主要文件有libphp4.a, libphp4.so等。
获取PHP源码的地址为:
http://php.net
取得的文件为php-4.0.1pl2.tar.gz,放于/usr/src目录下。
进入/usr/src目录并解压文件:
cd /usr/src
tar xzvf php-4.0.1pl2.tar.gz
命令完成后多了一个子目录php-4.0.1pl2,PHP的源码文件就在其中。
进入该子目录:
cd php-4.0.1pl2
该目录中的INSTALL文件详细介绍了如何安装PHP,照章行事即可。
配置生成Makefile文件:
./configure '--with-apxs=/usr/sbin/apxs' '--with-mysql' '--with-config-file-path=/etc/httpd' '--enable-safe-mode' '--with-system-regex' '--disable-debug' '--with-zlib' '--enable-magic-quotes' '--enable-track-vars' '--with-jpeg-dir=/usr/local' '--with-gd=/usr/local'
注意最后一行参数'--with-jpeg-dir=/usr/local' '--with-gd=/usr/local',指明了Jpeg和GD的目录为/usr/local,这是根据步骤1、2中make install的结果而指定的。
(由于命令太长,建议写成shell文件再执行。文件my-php-conf内容如下:
#! /bin/sh
./configure '--with-apxs=/usr/sbin/apxs' '--with-mysql' '--with-config-file-path=/etc/httpd' '--enable-safe-mode' '--with-system-regex' '--disable-debug' '--with-zlib' '--enable-magic-quotes' '--enable-track-vars' '--with-jpeg-dir=/usr/local' '--with-gd=/usr/local'
用shell执行之:
sh my-php-conf
效果是一样的。)
命令完成后该目录下多了个Makefile文件。
编译并安装:
make
make install
命令完成后,libphp4.so被拷到/usr/lib/apache目录下。
4、 Apache的配置
Apache本身不必重新编译安装,但使用了新的PHP,须让Apache知道,得修改Apache的配置文件并重启Apache服务。
修改Apache配置文件/etc/httpd/conf/httpd.conf,使得文件中包含以下几行:
LoadModule php4_module modules/libphp4.so
AddModule mod_php4.c
AddType application/x-httpd-php .php3 .php
同时注意把旧的php3的相应行注释掉,否则会出现冲突而使Apache重启失败。
重启Apache服务:
/etc/rc.d/init.d/httpd restart
5、 实例测试
再次按步骤0的说明检查当前状态,我已经看到,PHP改成了新的版本号,GD库也同时支持GIF和JPEG了。
但我还是想用实例来测试一下,这个例子的功能是读取一个gif文件,生成缩图,然后保存为另一个jpg文件。文件create-thumb.php的内容如下:
function CreateThumbnail($srcFile, $dstFile, $dstW, $dstH)
{
$data = GetImageSize($srcFile,&$info);
switch ($data[2]) {
case 1:
$im = @ImageCreateFromGIF($srcFile);
break;
case 2:
$im = @ImageCreateFromJPEG($srcFile);
break;
case 3:
$im = @ImageCreateFromPNG($srcFile);
break;
}
$srcW=ImageSX($im);
$srcH=ImageSY($im);
if ($srcW ImageJPEG($im,$dstFile);
else
{
if(($srcW / $srcH) > ($dstW / $dstH))
$dstH = $dstW * $srcH / $srcW;
else
$dstW = $dstH * $srcW / $srcH;
$ni=ImageCreate($dstW,$dstH);
ImageCopyResized($ni,$im,0,0,0,0,$dstW,$dstH,$srcW,$srcH);
ImageJPEG($ni,$dstFile);
}
}
CreateThumbnail("./test.gif", "./test-tn.jpg", 80, 80);
?>
把该文件放于Apahce的文档目录下(/etc/httpd/html),同时把测试用的图像文件test.gif也放于该目录下,然后用浏览器打开该php文件(我的hostname为zhangzh):
http://zhangzh/create-thumb.php
没出错信息。再看Apahce的文档目录(/etc/httpd/html),多了一个缩图文件test-tn.jpg。
大功告成,班师回朝。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











When deleting or decompressing a folder on your computer, sometimes a prompt dialog box "Error 0x80004005: Unspecified Error" will pop up. How should you solve this situation? There are actually many reasons why the error code 0x80004005 is prompted, but most of them are caused by viruses. We can re-register the dll to solve the problem. Below, the editor will explain to you the experience of handling the 0x80004005 error code. Some users are prompted with error code 0X80004005 when using their computers. The 0x80004005 error is mainly caused by the computer not correctly registering certain dynamic link library files, or by a firewall that does not allow HTTPS connections between the computer and the Internet. So how about

If you have used Docker, you must understand daemons, containers, and their functions. A daemon is a service that runs in the background when a container is already in use in any system. Podman is a free management tool for managing and creating containers without relying on any daemon such as Docker. Therefore, it has advantages in managing containers without the need for long-term backend services. Additionally, Podman does not require root-level permissions to be used. This guide discusses in detail how to install Podman on Ubuntu24. To update the system, we first need to update the system and open the Terminal shell of Ubuntu24. During both installation and upgrade processes, we need to use the command line. a simple

While studying in high school, some students take very clear and accurate notes, taking more notes than others in the same class. For some, note-taking is a hobby, while for others, it is a necessity when they easily forget small information about anything important. Microsoft's NTFS application is particularly useful for students who wish to save important notes beyond regular lectures. In this article, we will describe the installation of Ubuntu applications on Ubuntu24. Updating the Ubuntu System Before installing the Ubuntu installer, on Ubuntu24 we need to ensure that the newly configured system has been updated. We can use the most famous "a" in Ubuntu system

Widgets are a new feature of the Win11 system. They are turned on by default. However, it is inevitable that some users do not use widgets very much and want to disable them because they take up space. So how should they do this? The editor below will teach you how to operate it, and you can try it out. What are widgets? Widgets are small cards that display dynamic content from your favorite apps and services on your Windows desktop. They appear on the widget board, where you can discover, pin, unpin, arrange, resize, and customize widgets to reflect your interests. The widget board is optimized to display relevant widgets and personalized content based on usage. Open the widget panel from the left corner of the taskbar, where you can see live weather

Detailed steps to install Go language on Win7 computer Go (also known as Golang) is an open source programming language developed by Google. It is simple, efficient and has excellent concurrency performance. It is suitable for the development of cloud services, network applications and back-end systems. . Installing the Go language on a Win7 computer allows you to quickly get started with the language and start writing Go programs. The following will introduce in detail the steps to install the Go language on a Win7 computer, and attach specific code examples. Step 1: Download the Go language installation package and visit the Go official website

Installing Go language under Win7 system is a relatively simple operation. Just follow the following steps to successfully install it. The following will introduce in detail how to install Go language under Win7 system. Step 1: Download the Go language installation package. First, open the Go language official website (https://golang.org/) and enter the download page. On the download page, select the installation package version compatible with Win7 system to download. Click the Download button and wait for the installation package to download. Step 2: Install Go language

The os.Rename function is used in Go language to rename files. The syntax is: funcRename(oldpath,newpathstring)error. This function renames the file specified by oldpath to the file specified by newpath. Examples include simple renaming, moving files to different directories, and ignoring error handling. The Rename function performs an atomic operation and may only update directory entries when the two files are in the same directory. Renames may fail across volumes or while a file is in use.

The mobile version of WeChat Reading App is a very good reading software. This software provides a lot of books. You can read them anytime, anywhere with just one click to search and read them online. All of them are officially authorized and different types of books are neatly arranged. Sort and enjoy a comfortable and relaxing reading atmosphere. Switch the reading modes of different scenarios, update the latest book chapters continuously every day, support online login from multiple devices, and batch download to the bookshelf. You can read it with or without the Internet, so that everyone can discover more knowledge from it. Now the editor details it online Promote the method of viewing the catalog for WeChat reading partners. 1. Open the book you want to view the catalog and click in the middle of the book. 2. Click the three lines icon in the lower left corner. 3. In the pop-up window, view the book catalog
