Teach you to use PHP to create a thumbnail tutorial

Source: Internet
Author: User

With the rapid development of Web applications today, the major sites are springing up, but the thumbnail is the most indispensable content of the site, then how to use the Web application code to create a thumbnail? Below I will teach you how to use PHP code to make thumbnail images!

<?php

Header (' Content-type:image/jpeg ');

Sets the MIME type of the page to be a JPG picture type.

List ($width, $height) = getimagesize (' yuzhuo520.com.jpg ');

Get the original picture of the length and height, the getimagesize () function can get a picture of the information.

$new _width = $width * 0.2;

Calculates the width of the new graph after zooming.

$new _height = $height * 0.2;

Calculates the length of the new graph after zooming.

$new _img = Imagecreatetruecolor ($new _width, $new _height);

Create a thumbnail canvas to depict the thumbnail image.

$img = Imagecreatefromjpeg (' yuzhuo520.com.jpg ');

Load the image you want to zoom in.

Imagecopyresampled ($new _img, $img, 0,0,0,0, $new _width, $new _height, $width, $height);

Zoom in and copy the loaded image onto the canvas of the thumbnail $new_img you just created.

Imagejpeg ($new _img,null,100);

/*

* If the output is in JPEG format can add the 2nd do not need, with null over a bit,

* The 3rd parameter, which is a 0-100 number, indicates the sharpness of the picture. If it is in PNG format

* Output is not allowed to add 2nd and 3rd parameters, because PNG is full HD.

*  */

Imagedestroy ($IMG);

Although the original image does not need to be output, but in order to conserve server resources, it is not necessary to release it later.

Imagedestroy ($new _img);

Frees the resources used by the thumbnail image.

?>

According to the above steps to make thumbnails not only effectively improve the efficiency, saving manpower and resources and the effect of the thumbnail image is generous, this method can meet the most small and medium-sized Web site list page production thumbnail requirements, Small and medium-sized enterprise website Webmaster Friends and those who are not too familiar with PHP program friends can also be directly applied to quickly achieve the image zoom!

Yucho crosstalk Sketch Network original works http://www.yuzhuo520.com/reprint retain copyright and link, piracy must investigate!

Teach you to use PHP to create a thumbnail tutorial

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.