Code for php GD library to upload images and create thumbnails

WBOY
Release: 2016-07-25 09:04:10
Original
971 people have browsed it
  1. Image upload- bbs.it-home.org
  2. File upload (only jpg type images are allowed to be uploaded)



Copy code

2. Process page upload_img.php

  1. //Upload image saving address

  2. $uploadfile = "upfiles/".$_FILES['upfile']['name'];
  3. //Thumbnail saving Address
  4. $smallfile = "upfiles/small_".$_FILES['upfile']['name'];

  5. if($_FILES['upfile']['type'] ! = "image/jpeg")
  6. {
  7. echo 'Wrong file type';
  8. }
  9. else
  10. {
  11. move_uploaded_file($_FILES['upfile']['tmp_name'],$uploadfile); //Upload file
  12. $dstW=200;//Thumbnail width

  13. $dstH=200;//Thumbnail height

  14. $src_image=ImageCreateFromJPEG($uploadfile);

  15. $srcW =ImageSX($src_image); //Get the image width
  16. $srcH=ImageSY($src_image); //Get the image height

  17. $dst_image=ImageCreateTrueColor($dstW,$dstH);

  18. ImageCopyResized($dst_image,$src_image,0,0,0,0,$dstW,$dstH,$srcW,$srcH);
  19. ImageJpeg($dst_image,$smallfile);

  20. echo 'File uploaded successfully
    ';

  21. echo "";
  22. }
  23. ?>

Copy the code

the above code, It is relatively simple. Friends who are interested can study the gd library function in the PHP manual.



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template