Problem: after the blue dot Linux2.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, because GIF uses the copyrighted LZW algorithm, it may cause legal problems, so from the beginning of the GD-1.6, GD library no longer support GIF, changed to support better, no copyright contention problem: install blue point Linux 2.0, PHP programming, found that only processing GIF images, JPEG images cannot be processed. Later, I learned that PHP used the GD library to process images, and the GD Library started to support GIF. However, because GIF uses the copyrighted LZW algorithm, it may cause legal problems, so from the beginning of the GD-1.6, GD library no longer support GIF, changed to support better, no copyright dispute 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, PHP-4.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:
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 normally, 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. installation and configuration of ipv6b
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.
The URL for obtaining Jpeg source code is:
Ftp://ftp.uu.net/graphics/jpeg/
The obtained file is src.v6b.tar.gz, which is stored in the/usr/src directory.
Go to the/usr/src directory and start the installation process.
Enter/usr/src:
Cd/usr/src
Uncompress the file:
Tar xzvf restart src.v6b.tar.gz
After the command is completed, a sub-directory jpeg-6b is added, and the source file of Jpeg is in it.
Enter this subdirectory:
Cd jpeg-6b
The install.doc file in this directory describes in detail how to install Jpeg, just follow the instructions.
Configure to generate the Makefile file:
./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 complete, export lib. h is copied to the/usr/local/include directory, and libjpeg. a and libjpeg. so are 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:
Patch-p0 After the 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.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.