Problem: After Blue Point Linux 2.0 is installed, PHP programming can only process GIF images, but not JPEG images. Later I learned that PHP used the GD library to process images, and the GD library started to support GIF. However, due to the use of the copyrighted LZW Algorithm , Will cause legal issues, so from the beginning of the GD-1.6, GD library no longer support GIF, changed to support better, without copyright disputes PNG. Now I want to support both GIF, PNG and JPEG. After trying, I successfully achieved this. The following describes the specific practices. My configuration is: blue dot Linux 2.0, kernel-2.2.16, MySQL-3.23.10alpha, APACHE-1.3.12, php4.0.1pl2, gd-1.8.3, rj6b.
I will introduce it in the bottom-up order, that is, JPEG-> Gd-> PHP-> Apache.
0. view the current status
After the blue-dot Linux 2.0 is installed, no changes have been made to kernel, MySQL, and Apache to see how the current status is.
Create a PHP file named info. php, which is stored in the directory of apahce (/etc/httpd/html). Its content is as follows:
<? Phpinfo ();?>
The file has only one line. Open the File URL in a browser (My hostname is zhangzh ):
Http: // zhangzh/info. php
If Apache/PHP runs properly, the PHP version, Apache version, and other useful information will be listed on the page. I am concerned about the GD library and check whether it supports GIF and JPEG. The result shows that it supports GIF instead of JPEG.
1. install and configure jpeg6b
the main JPEG files include jpeglib. H, libjpeg. A, and libjpeg. So. First, check whether the image is installed. Check whether the image Lib. H is installed in the/usr/include directory. Check whether the image libjpeg. A and libjpeg. So are available in the/usr/include directory. I do not have it in my system, so I need to install it.
Get JPEG Source Code address:
ftp://ftp.uu.net/graphics/jpeg/
the obtained file is src.v6b.tar.gz, stored in the/usr/src directory.
go to the/usr/src directory and start the installation process.
enter/usr/src:
Cd/usr/src
To uncompress the file:
tar xzvf unzip src.v6b.tar.gz
after the command is completed, a sub-directory jpeg-6b is added, and the JPEG source code file is in it.
enter the subdirectory:
Cd jpeg-6b
the install.doc file in the directory describes in detail how to install JPEG, follow the instructions.
Generate makefile:
./configure
after the command is complete, multiple makefile files are added to the directory. Makefile is a lot of software compilation and installation configuration and process control files, it is very important to learn to understand its content.
Start Compilation:
make
after the command is complete, many files are added to the directory, including libjpeg. A and libjpeg. So.
Installation:
make install
after the command is completed, unzip Lib. H is copied to the/usr/local/include directory, libjpeg. A And libjpeg. so is copied to the/usr/local/lib directory.
2. installation and configuration of GD-1.8.3
The main files of GD include GD. h and libgd..
The address for getting GD source code is:
Http://www.boutell.com/gd/
The obtained file is gd-1.8.3.tar.gz, which is stored in the/usr/src directory.
I already know that GD of this version does not support GIF, But I want many people who want GD to support both GIF and JPEG, so someone has made a patch, added the support for GIF. It looks like an English man. His e-mail address is adam@elysium.ltd.uk.
The address for obtaining the patch source code is:
Http://www.webofsin.com/gd-1.8.3-gif.patch
The obtained file is a gd-1.8.3-gif.patch and stored in the/usr/src directory.
Enter/usr/src:
CD/usr/src
Uncompress the file:
Tar xzvf gd-1.8.3.tar.gz
After the command is completed, a sub-directory gd-1.8.3 is added, and the source code file of GD is in it.
Patch the source code:
After the patch-P0 command is complete, there are multiple gd_gif.c files in the gd-1.8.3 subdirectory, and the files GD. h and makefile are modified accordingly.
Enter this subdirectory:
CD gd-1.8.3
By default, the GD library does not support JPEG compilation. You must modify the MAKEFILE file.
Modify the MAKEFILE file so that:
Cflags =-o-dhave_xpm-dhave_jpeg-dhave_libttf
Libs =-lm-LGD-lpng-LZ-ljpeg-lttf-lxpm-lx11
After that, compile and install:
Make
Make install
After the command is complete, Gd. H is copied to the/usr/local/include directory, and libgd. A is copied to the/usr/local/lib directory.
3. installation and configuration of PHP-4.0.1pl2
The main PHP files include libphp4.a and libphp4.so.
The address for obtaining the PHP source code is:
Http://php.net
The obtained file is php-4.0.1pl2.tar.gz, which is stored in the/usr/src directory.
Go to the/usr/src directory and decompress the file:
CD/usr/src
Tar xzvf php-4.0.1pl2.tar.gz
After the command is completed, a sub-directory php-4.0.1pl2 is added, and the PHP source code file is in it.
Enter this subdirectory:
CD php-4.0.1pl2
The Install file in this directory describes in detail how to install PHP.
Configure to generate the MAKEFILE file:
./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'
Note that the last line parameter '-- With-JPEG-Dir =/usr/local'' -- With-Gd =/usr/local ', the Directory of JPEG and GD is/usr/local, which is specified based on the result of make install in steps 1 and 2.
(Because the command is too long, it is recommended to write it as a shell file and then execute it. The content of the my-PHP-conf file is as follows:
#! /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'
Run it in shell:
Sh my-PHP-Conf
The results are the same .)
After the command is complete, multiple makefile files are added to the directory.
Compile and install:
Make
Make install
After the command is complete, libphp4.so is copied to the/usr/lib/Apache directory.
4. Apache configuration
Apache itself does not need to be re-compiled and installed, but with the new PHP, you must let Apache know that you must modify the Apache configuration file and restart the apache service.
Modify the Apache configuration file/etc/httpd/CONF/httpd. conf so that the file contains the following lines:
Loadmodule php4_module modules/libphp4.so
Addmodule mod_php4.c
Addtype application/X-httpd-PHP. php3. php
At the same time, note that the corresponding lines of the old php3 are commented out. Otherwise, the Apache restart will fail due to a conflict.
Restart the apache service:
/Etc/rc. d/init. d/httpd restart
5. instance Test
Check the current status again according to step 0. I have seen that PHP is changed to a new version number, and the GD library supports both GIF and JPEG versions.
But I still want to test it with an instance. The function of this example is to read a GIF file, generate a thumbnail, and save it as another JPG file. The contents of the file create-thumb.php are as follows:
<?
Function createthumbnail ($ srcfile, $ dstfile, $ dstw, $ dsomething)
{
$ 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 <= $ dstw & $ srch <= $ DTH)
Imagejpeg ($ im, $ dstfile );
Else
{
If ($ srcw/$ srch)> ($ dstw/$ dsomething ))
$ Dsomething = $ dstw * $ srch/$ srcw;
Else
$ Dstw = $ dsomething * $ srcw/$ srch;
$ Ni = imagecreate ($ dstw, $ dsomething );
Imagecopyresized ($ Ni, $ im, 0, 0, 0, $ dstw, $ dsomething, $ srcw, $ srch );
Imagejpeg ($ Ni, $ dstfile );
}
}
Createthumbnail ("./test.gif", "./test-tn.jpg", 80, 80 );
?>
Put this file in the apahce document directory (/etc/httpd/html#, and also store the test.gif image file for testing in this directory, and then open the PHP file in a browser (My hostname is zhangzh ):
Http: // zhangzh/create-thumb.php
No error message. Check the directory of apahce (/etc/httpd/html#, and add another thumbnail file test-tn.jpg.
It was done, and the class teacher went back to the DPRK.