Question: After installing Bluepoint Linux 2.0, I started programming in PHP and found that it could only process GIF images, not JPEG images. Later I learned that PHP uses the GD library to process images, and the GD library initially supported GIF. However, because GIF used the copyright-controversial LZW algorithm, it would cause legal problems, so starting from GD-1.6, the GD library no longer supports it. GIF, instead support the better, copyright-free PNG. And now I want to support GIF, PNG and JPEG at the same time. After trying it out, I managed to do this. The specific methods are introduced below. My configuration is: Bluepoint Linux 2.0, Kernel-2.2.16, MySQL-3.23.10alpha, Apache-1.3.12, PHP4.0.1pl2, gd-1.8.3, Jpeg6b.
I will introduce it in order from bottom to top, that is, Jpeg->GD->PHP->Apache.
0. Check the current status
After installing Bluepoint Linux 2.0, Kernel, MySQL, and Apache have not made any changes. Check the current status.
Create a PHP file named info.php and place it in the Apahce document directory (/etc/httpd/html). Its content is as follows:
The file only has 1 line. Open the file URL with a browser (my hostname is zhangzh):
http://zhangzh/info.php
If Apache/PHP is running normally, the PHP version and Apache version will be listed on the page. and various other useful information. What I was concerned about was the GD library part to see if it supports GIF and JPEG. It turned out that it supports GIF but not JPEG.
1. Installation and configuration of Jpeg6b
The main files of Jpeg include jpeglib.h, libjpeg.a, libjpeg.so, etc. First check whether it is installed in the system. Go to the /usr/include directory to see if there is jpeglib.h, and go to the /usr/lib directory to see if there are libjpeg.a and libjpeg.so. My system does not have it, so I need to install it.
The address to obtain the Jpeg source code is:
ftp://ftp.uu.net/graphics/jpeg/
The obtained file is jpegsrc.v6b.tar.gz and placed in the /usr/src directory .
Go to the /usr/src directory and start the installation process.
Enter /usr/src:
cd /usr/src
Unzip the compressed file:
tar xzvf jpegsrc.v6b.tar.gz
After the command is completed, there is an additional subdirectory jpeg- 6b, the Jpeg source code file is in it.
Enter this subdirectory:
cd jpeg-6b
The install.doc file in this directory details how to install Jpeg, just follow the instructions.
Configure and generate a Makefile file:
./configure
After the command is completed, there will be an additional Makefile file in the directory. Makefile is a configuration and process control file for compilation and installation of many software. It is very important and you should learn to understand its contents.
Start compiling:
make
After the command is completed, there are many more files in the directory, the important ones are libjpeg.a and libjpeg.so.
Installation:
make install
After the command is completed, jpeglib.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, libgd.a, etc.
The address to obtain the GD source code is:
http://www.boutell.com/gd/
The obtained file is gd-1.8.3.tar.gz, which is placed in the /usr/src directory .
It is known that this version of GD does not support GIF, but thinking about it, there are many people like me who hope that GD supports both GIF and JPEG, so someone made a patch to add support for GIF. It seems that this is a British man, his email address is adam@elysium.ltd.uk.
The address to obtain the patch source code is:
http://www.webofsin.com/gd-1.8.3-gif.patch
The obtained file is gd-1.8.3-gif.patch, put In the /usr/src directory.
Enter /usr/src:
cd /usr/src
Unzip the compressed file:
tar xzvf gd-1.8.3.tar.gz
After the command is completed, there is an additional subdirectory gd-1.8.3, the source code files of GD are in it.
Patch the source code:
patch -p0 After the command is completed, there is an additional gd_gif.c file in the gd-1.8.3 subdirectory, and the files gd.h and Makefile have also been modified accordingly.
Enter this subdirectory:
cd gd-1.8.3
By default, the GD library does not include JPEG support when compiling, so the Makefile must be modified.
Modify the Makefile so that:
CFLAGS=-O -DHAVE_XPM -DHAVE_JPEG -DHAVE_LIBTTF
LIBS=-lm -lgd -lpng -lz -ljpeg -lttf -lXpm -lX11
Thereafter, compile and Installation:
make
make install
After the command is completed, 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 files of PHP include libphp4.a, libphp4.so, etc.
The address to obtain the PHP source code is:
http://php.net
The obtained file is php-4.0.1pl2.tar.gz, which is placed in the /usr/src directory.
Enter the /usr/src directory and extract the file:
cd /usr/src
tar xzvf php-4.0.1pl2.tar.gz
After the command is completed, there is an additional subdirectory php-4.0. 1pl2, the source code file of PHP is in it.
Enter this subdirectory:
cd php-4.0.1pl2
The INSTALL file in this directory details how to install PHP, just follow the instructions.
Configure the generated 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-track-vars'
'--with-jpeg-dir=/usr/local' '--with-gd=/usr/local'
Pay attention to the last line of parameters '--with -jpeg-dir=/usr/local' '--with-gd=/usr/local' specifies that the directory of Jpeg and GD is /usr/local, which is specified based on the results of make install in steps 1 and 2. of.
(Because the command is too long, it is recommended to write it as a shell file and then execute it. The content of the file my-php-conf 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' /local' '--with-gd=/usr/local'
Use shell to execute:
sh my-php-conf
The effect is the same)
After the command is completed, go to this directory. There is one more Makefile.
Compile and install:
make
make install
After the command is completed, libphp4.so is copied to the /usr/lib/apache directory.
4. Apache configuration
Apache itself does not need to be recompiled and installed, but if you use 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_modulemodules/libphp4.so
AddModule mod_php4.c
AddTypeapplication/x -httpd-php .php3 .php
At the same time, be sure to comment out the corresponding lines of the old php3, otherwise conflicts will occur and Apache will fail to restart.
Restart the Apache service:
/etc/rc.d/init.d/httpd Restart
5. Instance test
Check the current status according to the instructions in step 0 again, I have seen , PHP has been changed to a new version number, and the GD library also supports both GIF and JPEG.
But I still want to test it with an example. The function of this example is to read a gif file, generate a thumbnail, and then save it as another jpg file. The content of the file create-thumb.php is as follows:
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); $im);
$srcH=ImageSY($im);
if ($srcW <= $dstW && $srcH <= $dstH)
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);
?>
Put this file in the document directory of Apahce (/etc/httpd/html), and also put the test image file test.gif in this directory, and then open the php file with a browser (my hostname is zhangzh):
http://zhangzh/create-thumb.php
No error message. Looking at the Apahce document directory (/etc/httpd/html), there is an additional thumbnail file test-tn.jpg.
Done, the class teacher returns to the court.
http://www.bkjia.com/PHPjc/315210.html
www.bkjia.com