Configure PHP to support both the GIF and jpeg_php tutorials

Source: Internet
Author: User
Tags file url imagejpeg php source code unpack vars
Issue: After installing the Blue Dot Linux 2.0, PHP was programmed to find that only GIF images could be processed and JPEG images could not be processed. Later know that PHP processing images, using the GD library, and the GD library started with GIF support, but because GIF uses a copyright dispute LZW algorithm, will cause legal problems, so from GD-1.6, GD Library no longer support GIF, instead of support for better, no copyright dispute png. And I now want to support both gif,png and JPEG. After trying, I succeeded in doing this. The following describes the practice. 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,jpeg6b.





I'll follow the bottom-up sequence, which is jpeg->gd->php->apache.

0. View current status
After installing the Blue Dot Linux 2.0, Kernel,mysql,apache did not make any changes to see what the current state is.
Create a php file named info.php, placed in the APAHCE document directory (/etc/httpd/html), with the following contents:

The file is only 1 lines. Open the file URL with your browser (my hostname is ZHANGZH):
http://zhangzh/info.php
If the apache/php is working properly, the PHP version, the Apache version, and any other useful information will be listed on the page. I am concerned about the GD library section to see if it supports GIF, JPEG, and the result is that GIF is supported and does not support JPEG.

1, the installation and configuration of jpeg6b
The main files of JPEG are jpeglib.h, LIBJPEG.A, libjpeg.so and so on. First check the system installed no, to the/usr/include directory to see if there is no jpeglib.h, to/usr/lib directory to see if there is no libjpeg.a and libjpeg.so. Not in my system, so I want to install it.
The address for obtaining 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.
Enter the/USR/SRC directory to begin the installation process.
Enter/USR/SRC:
Cd/usr/src
To unpack a compressed file:
Tar xzvf jpegsrc.v6b.tar.gz
After the command is completed, a subdirectory jpeg-6b,jpeg the source file is in it.
Enter this subdirectory:
CD jpeg-6b
The Install.doc file in this directory details how to install the JPEG and Teruaki acts.
To configure the build makefile file:
./configure
After the command is complete, the directory has more than one makefile file. Makefile files are a lot of software compiled, installed configuration and process control files, it is very important to learn to understand its content.
To start compiling:
Make
After the command is complete, there are many more files in the directory, of which LIBJPEG.A and libjpeg.so are important.
Installation:
Make install
After the command is completed, Jpeglib.h is copied to the/usr/local/include directory, LIBJPEG.A and libjpeg.so are copied to the/usr/local/lib directory.

2, the installation and configuration of GD-1.8.3
GD's main documents are gd.h, LIBGD.A and so on.
The address for obtaining GD source code is:
http://www.boutell.com/gd/
The obtained file is gd-1.8.3.tar.gz and placed in the/USR/SRC directory.
It is known that the version of GD does not support GIF, but like I hope that GD also support GIF and JPEG a lot of people, so someone made a patch, the GIF support added back. Looks like this is an Englishman, his email address is adam@elysium.ltd.uk.
Get the patch source address as:
Http://www.webofsin.com/gd-1.8.3-gif.patch
The obtained file is gd-1.8.3-gif.patch and placed in the/USR/SRC directory.
Enter/USR/SRC:
Cd/usr/src
To unpack a compressed file:
Tar xzvf gd-1.8.3.tar.gz
After the command is completed, a subdirectory gd-1.8.3,gd the source file is in it.
To patch the source code:
After the PATCH-P0 command is completed, the gd-1.8.3 sub-directory has a GD_GIF.C file, and the file Gd.h and makefile are modified accordingly.
Enter this subdirectory:
CD gd-1.8.3
By default, the GD library compiles without JPEG support and modifies the makefile file.
Modify the makefile file to make:
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 completed, Gd.h is copied to the/usr/local/include directory, LIBGD.A is copied to the/usr/local/lib directory.

3, the installation and configuration of PHP-4.0.1PL2
PHP main files are libphp4.a, libphp4.so and so on.
To get the PHP source code address is:
Http://php.net
The obtained file is php-4.0.1pl2.tar.gz and placed in the/USR/SRC directory.
Enter the/USR/SRC directory and unzip the file:
Cd/usr/src
Tar xzvf php-4.0.1pl2.tar.gz
After the command is completed, a subdirectory php-4.0.1pl2,php the source file is in it.
Enter this subdirectory:
CD PHP-4.0.1PL2
The install file in this directory details how to set up PHP, and Teruaki can act on it.
To configure the build 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 of parameters '--with-jpeg-dir=/usr/local '--with-gd=/usr/local ' indicates the JPEG and GD directories are/usr/local, which is based on the make in steps 1, 2 The result of the install is specified.
(because the command is too long, it is recommended to write it as a shell file.) The file my-php-conf content 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 '
Executed with the shell:
SH my-php-conf
The effect is the same. )
After the command is complete, the directory has more than one makefile file.
Compile and install:
Make
Make install
When the command is complete, libphp4.so is copied to the/usr/lib/apache directory.

4. Apache Configuration
Apache itself does not have to recompile the installation, but using the new PHP, you have to let Apache know that you have to 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
Also note that the corresponding line of the old PhP3 is commented out, otherwise there will be a conflict and the Apache restart failed.
To restart the Apache service:
/ETC/RC.D/INIT.D/HTTPD restart

5. Example Test
Check the current status again as described in step 0, I have seen that PHP has been changed to a new version number, and the GD library 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 contents of the file create-thumb.php are 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);
Break
}
$srcW =imagesx ($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 the file in the Apahce document directory (/etc/httpd/html), and also put the test image file Test.gif in the directory, and then open the PHP file with a browser (my hostname for ZHANGZH):
http://zhangzh/create-thumb.php
No error message. Then look at the APAHCE document directory (/etc/httpd/html), more than a thumbnail file test-tn.jpg.

Finished, cavalry back toward.


http://www.bkjia.com/PHPjc/315210.html www.bkjia.com true http://www.bkjia.com/PHPjc/315210.html techarticle issue: After installing the Blue Dot Linux 2.0, PHP was programmed to find that only GIF images could be processed and JPEG images could not be processed. Later know that PHP processing images, the use of the GD library, and the GD library began to support ...

  • Related Article

    Contact Us

    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.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.