Simple image generation thumbnails

Source: Internet
Author: User
The name of the newly generated thumbnail $ filename image, including the path

Create a thumbnail for the newly created image

 

PHP code
  1. // The file
  2. $ Filename = 'mm.jpg ';
  3. $ DstFile = "icons /";
  4. $ FilePath = "icons/test.jpg ";
  5. // Set a maximum height and width
  6. $ Width = 100;
  7. $ Height = 100;
  8. // Content type
  9. Header ('content-type: image/jpeg ');
  10. // Get new dimensions
  11. List ($ width_orig, $ height_orig) = getimagesize ($ filename );
  12. If ($ width & ($ width_orig <$ height_orig )){
  13. $ Width = ($ height/$ height_orig) * $ width_orig;
  14. } Else {
  15. $ Height = ($ width/$ width_orig) * $ height_orig;
  16. }
  17. // Resample
  18. $ Image_p = imagecreatetruecolor ($ width, $ height );
  19. $ Image = imagecreatefromjpeg ($ filename );
  20. Imagecopyresampled ($ image_p, $ image, 0, 0, 0, 0, $ width, $ height, $ width_orig, $ height_orig );
  21. // Output
  22. Imagejpeg ($ image_p, $ filePath );
  23. ?>

$ Filename: image name, including Path


$ DstFile target path


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.