Home >Backend Development >PHP Tutorial >PHP implements image scaling (experts have passed by)

PHP implements image scaling (experts have passed by)

WBOY
WBOYOriginal
2016-07-25 08:49:091042browse
PHP implements 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. * 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 image size
  18. list($s_w,$s_h)=getimagesize($source);
  19. //Generate 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


Statement:
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