Implementation of native thumbnails in PHP

Source: Internet
Author: User
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 ('.'

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.