How to create image thumbnails using the GD Library in php

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

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.