Use php to zoom in and out images)

Source: Internet
Author: User
Use php to zoom in and out images)
Php enables simple image scaling.

  1. /**
  2. * The Images class is an image processing class.
  3. * @ Author pan
  4. * @ Package application. controllers
  5. * @ Since 1.0
  6. */
  7. Class Images
  8. {
  9. /**
  10. * Scale an image
  11. * @ Param $ source original image
  12. * @ Param $ newfile New Image
  13. * @ Param $ pre zoom ratio
  14. */
  15. Public function thumn ($ source, $ pre, $ newfile)
  16. {
  17. // Obtain the image size
  18. List ($ s_w, $ s_h) = getimagesize ($ source );
  19. // Generate a new image size
  20. $ New_w = $ s_w * $ pre;
  21. $ New_h = $ s_h * $ pre;
  22. // Create a new image
  23. $ New_f = imagecreatetruecolor ($ new_w, $ new_h );
  24. // Create an image with a resource image
  25. $ Sour_f = imagecreatefromjpeg ($ source );
  26. // Copy the resource image to the new image
  27. Imagecopyresampled ($ new_f, $ sour_f, 0, 0, 0, 0, $ new_w, $ new_h, $ s_w, $ s_h );
  28. // Output the image to the browser
  29. Imagejpeg ($ new_f, $ newfile );
  30. Imagedestroy ($ new_f );
  31. Imagedestroy ($ sour_f );
  32. }
  33. }
  34. ?>

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.