This article mainly introduces how php uses the GD library to create image thumbnails. it involves some skills related to using the GD library to operate images in php, for more information about how to create image thumbnails using the GD Library in php, see the following example. Share it with you for your reference. The specific analysis is as follows:
Upload the static html code of the page:
File Upload
File Upload
The corresponding Upload. php file code:
<? Php $ uploadfile = "upfiles /". $ _ FILES ['upfile'] ['name']; // name and path of the uploaded file $ smallfile = "upfiles/small _". $ _ FILES ['upfile'] ['name']; // name and path of the uploaded thumbnail file if ($ _ FILES ['upfile'] ['type']! = "Image/pjpeg") {echo "file type error "; // output error message} else {move_uploaded_file ($ _ FILES ['upfile'] ['tmp _ name'], $ uploadfile); // uploads a file $ dstW = 200; // set the width of the thumbnail. $ dsomething = 200; // set the height of the thumbnail. $ src_image = ImageCreateFromJPEG ($ uploadfile ); // read the JPEG file and create an image object $ srcW = ImageSX ($ src_image); // Obtain the image width $ srcH = ImageSY ($ src_image ); // Obtain the image height $ dst_image = ImageCreateTrueColor ($ dstW, $ DTH); // create a new image object ImageCopyResized ($ dst_image, $ src_image, $ dstW, $ dsomething, $ srcW, $ srcH); // redefines the image size and writes it to the new image object ImageJpeg ($ dst_image, $ smallfile ); // create the thumbnail file echo. the file has been uploaded.
"; // Output the uploaded information echo" "; // display the thumbnail on the page}?>
I hope this article will help you with php programming.