Configure PHP to support GIF and JPEG at the same time.

zhaozj2021-02-08  242

Configure PHP to support GIF and JPEG at the same time.

Zhang Zhonghua (Mike_Z@21cn.com)

Problem: After installing the blue dot Linux 2.0, perform PHP programming, discovery only the GIF image can be processed, and the JPEG image can not be processed. Later, I learned that PHP processing images, using the GD library, and the GD library starts to support GIF, but because GIF uses a copyright dispute, the LZW algorithm will cause legal issues, so from GD-1.6, the GD library is no longer supported GIF, change to support better, no copyright dispute. And I hope to support GIF, PNG and JPEG.

After trying, I successfully did this. Here is a specific practice. My configuration is: Blue Point Linux 2.0, Kernel-2.2.16, MySQL-3.23.10alpha, Apache-1.3.12, PHP-4.0.1PL2, GD-1.8.3, JPEG6B.

I will introduce in the order of the bottom, that is, JPEG-> gd-> php-> apache.

0, current status View

After installing the blue dot Linux 2.0, kernel, mysql, apache did not do any changes, see how the current state.

Create a PHP file, named Info.php, put in the document directory of APAHCE (/ etc / httpd / html), its contents are as follows:

There is only 1 line of the file. Open the file URL with a browser (my hostname is Zhangzh):

http://zhangn/info.php

If Apache / PHP is running normally, the PHP version, Apache version, and other useful information will be listed. I care about the GD library section, see if it supports GIF, JPEG, and finds that GIF is supported without JPEG.

1, JPEG6B installation and configuration

The main files of JPEG are JPEGLIB.H, LIBJPEG.A, LIBJPEG.SO, etc. First check the system installed in the system, to the / usr / include directory, there is no JPEGLIB.H, to the / usr / lib directory, there is loIPjpeg.a and libjpeg.so. There is no system in my system, so you have to install it.

Get the address of the JPEG source code:

ftp://ftp.u.net/graphics/jpeg/

The obtained file is jpegsrc.v6b.tar.gz, placed in the / usr / src directory.

Enter the / usr / src directory to start the installation process.

Enter / usr / src:

CD / USR / SRC

Unconverting the compressed file:

Tar Xzvf Jpegsrc.v6b.tar.gz

After the command is completed, there is more subdirectories JPEG-6B, and JPEG's source file is here.

Enter the subdirectory:

CD JPEG-6B

The install.doc file in this directory describes how to install JPEG and act as a chapter.

Configure the generated Makefile file:

./configure

After the command is completed, there is a Makefile file in this directory. Makefile file is a lot of software compilation, installation configuration and process control files, it is important to learn about its content.

Start compilation:

Make

After the command is completed, there are many files in this directory, which is important to libjpeg.a and libjpeg.so.

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, GD-1.8.3 installation and configuration

The main file of GD has GD.H, Libgd.a, etc.

Get the address of the GD source code:

http://www.boutell.com/gd/

The obtained file is GD-1.8.3.tar.gz, put in / usr / src directory.

It is known that the version of GD does not support GIF, but I want to want GD to support GIF and JPEG at the same time, so someone has made a patch, and put it back to GIF support. It seems that this is a British, his email address is adam@ed.uk.

Get the address of the patch source code:

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

Unconverting the compressed file:

TAR XZVF GD-1.8.3.Tar.gz

After the command is completed, there is a child directory GD-1.8.3, the source code file of GD is here.

Give the source code to patch:

PATCH -P0

After the command is completed, there is a GD_GIF.C file in the GD-1.8.3 subdirectory, and the file GD.H and Makefile have been modified accordingly.

Enter the subdirectory:

CD GD-1.8.3

By default, JPEG support is not added when the GD library is compiled, and you can 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

Since then, compile and install:

Make

Make Install

After the command is completed, GD.H is copied to the / usr / local / incline directory, libgd.a is copied to the / usr / local / lib directory.

3, PHP-4.0.1PL2 installation and configuration

The main file of PHP has libphp4.a, libphp4.so, etc.

Get the address of the PHP source code as:

http://php.net

The obtained file is PHP-4.0.1pl2.tar.gz, put it in the / usr / src directory.

Go to the / usr / src directory and decompressed files:

CD / USR / SRC

TAR XZVF PHP-4.0.1pl2.tar.gz

After the command is completed, there is a child directory PHP-4.0.1PL2, and the PHP source code file is here.

Enter the subdirectory:

CD PHP-4.0.1PL2

The Install file in this directory describes how to install PHP and act as an obstacle.

Configure the generated 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' '--Nable-TRACK-VARS' --WITH-JPEG-DIR = / USR / local '' --with-gd = / usr / local 'pay attention to the last line parameter' --with-jpeg-dir = / usr / local '' --with-gd = / usr / local ', specified JPEG The directory of GD is / usr / local, which is specified based on the results of the make install in steps 1, 2.

(Since the order is too long, it is recommended to write a shell file and then execute. 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' '--Nable-TRACK-VARS' --WITH-JPEG-DIR = / USR / LOCAL '--WITH-GD = / usr / local'

Execute it with the shell:

SH my-php-conf

The effect is the same. )

After the command is completed, there is a Makefile file in this directory.

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 have to recompile the installation, but use new PHP, you must let Apache know to modify the Apache profile and restart the Apache service.

Modify the apache profile /etc/httpd/conf/httpd.conf, make the following lines in the file:

LoadModule PHP4_Module Modules / Libphp4.so

AddModule MOD_PHP4.C

AddType Application / X-httpd-php .php3 .php

At the same time, pay attention to removing the appropriate line of the old PHP3, otherwise the conflict will cause the apache to restart failed.

Restart Apache Services ¼

/etc/rc.d/init.d/httpd restart

5, instance test

Press step 0 to check the current state, I have seen that PHP is changed to a new version number, and GD library also supports GIF and JPEG.

But I still want to use an instance to test, this example is to read a GIF file, generate a miniature, and 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 = ImageESY ($ 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 ($ N, $ 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), while putting the image file Test.gif for the test in this directory, then open the PHP file with your browser (my hostname is Zhangzh) ):

http://zhangn/create-thumb.php

No error message. Look at the APAHCE's documentation (/ etc / httpd / html), there is a minor file test-tn.jpg.

Dacheng, the class teacher returned.

From: http://zzh-cn.com

Date: 2000.11.09

转载请注明原文地址:https://www.9cbs.com/read-2498.html

New Post(0)