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