Home > Backend Development > PHP Tutorial > PHP achieves image zoom effect

PHP achieves image zoom effect

WBOY
Release: 2016-07-25 08:54:44
Original
1121 people have browsed it
  1. /**

  2. * Images class Image processing class
  3. * @author pan
  4. * @package application.controllers
  5. * @since 1.0
  6. */
  7. class Images
  8. {
  9. /**
  10. * Zoom 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. //Get 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 a 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. ?>

Copy code

The above is a simple code to implement image scaling in PHP for the reference of beginners.



Related labels:
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