What surprised us with PHP is that we need to worry about ASP in image processing. Using the GD Library PHP, we can easily implement thumbnails. In this article, we aim to use GD to create a thumbnail, PHP can directly deliver thumbnails to browsers by nature or surprise us with PHP, that is, to worry about ASP in image processing, you can easily implement thumbnails with the GD Library PHP. In this article, we aim to use GD to create a thumbnail. PHP can directly deliver the thumbnail to the browser or store it to the hard disk as a file.
In the process of creating a thumbnail, we need to use several functions in the GD Library:
Getimagesize (string filename [, array var]) to obtain the image information. the returned value is a one-person array, which contains several pieces of information $ var [0] ---- Return the width of the image, $ var [1] ---- Return height, [2] return the type of the image file. [4] returns the width = ''related to wdith and height in the returned value '', height = ''information.
ImageX (resource image)
ImageY (resource image) returns the width and height of the image
Imagecopyresized (des img, src img, int des_x, int des_y, int src_x, int src_y, int des_w, int des_h, int src_w, int src_y) copies and captures regional images.
Imagecreatetruecolor (int width, int height) creates a true color chart
Imagejpeg (resource image)
The following Code is used:
# Constants
Define (IMAGE_BASE, '/var/www/html/mbailey/images ');
Define (MAX_WIDTH, 150 );
Define (MAX_HEIGHT, 150 );
# Get image location
$ Image_file = str_replace ('..', '', $ _ SERVER ['query _ string']);
$ Image_path = IMAGE_BASE. '/$ image_file ';
# Load image
$ Img = null;
$ Ext = strtolower (end (explode ('.'