How PHP uses the GD library to create thumbnail images _php tips

Source: Internet
Author: User

This example describes how PHP uses the GD library to create thumbnail images of pictures. Share to everyone for your reference. The specific analysis is as follows:

Static HTML code for uploading pages:

 
 

The corresponding upload.php file code:

<?php 
$uploadfile = "upfiles/". $_files[' upfile ' [' name '];
The file name and path 
$smallfile = "Upfiles/small_" after the upload. $_files[' upfile ' [' name '];
File name and path 
if ($_files[' upfile '] [' type ']!= "Image/pjpeg") 
{ 
  echo "file type error";//Output error message 
} 
Else 
{ 
  move_uploaded_file ($_files[' upfile '] [' tmp_name '], $uploadfile);
  Upload file 
  $dstW = 200;//Set the width of the thumbnail 
  $dstH = 200;//Set the height of the thumbnail 
  $src _image = Imagecreatefromjpeg ($uploadfile); c16/>//reads the JPEG file and creates the image object 
  $srcW = Imagesx ($src _image);//Get the image wide 
  $srcH = Imagesy ($src _image);//Get high 
  $ for image Dst_image = Imagecreatetruecolor ($dstW, $dstH);
  Create a new Image Object 
  imagecopyresized ($dst _image, $src _image,0,0,0,0, $dstW, $dstH, $srcW, $srcH);
  Writes the image to the new Image object 
  imagejpeg ($dst _image, $smallfile) after the size is redefined;//create thumbnail file 
  echo "File upload complete <BR>"//Output Upload success Information 
  echo "</img>";
  Show thumbnails on the page 
} 
?>

I hope this article will help you with your PHP program design.

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.