Home >Backend Development >PHP Tutorial >php zoom image code

php zoom image code

WBOY
WBOYOriginal
2016-07-25 08:45:18924browse
  1. // Specify the file path and scaling ratio
  2. $filename = 'test.jpg';
  3. $percent = 0.5;
  4. // Specify the header file Content type value
  5. header('Content-type: image/jpeg');
  6. // Get the width and height of the image
  7. list($width, $height) = getimagesize($filename);
  8. $newwidth = $width * $percent;
  9. $newheight = $height * $percent;
  10. // Create an image. The received parameters are width and height respectively, and the generated resource handle is returned.
  11. $thumb = imagecreatetruecolor($newwidth, $newheight);
  12. //Get the source file resource handle. The received parameter is the image path and the handle is returned
  13. $source = imagecreatefromjpeg($filename);
  14. // Cut all fields of the source file and reduce it to the target image. The first two are resource handles
  15. imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
  16. // Output to the browser
  17. imagejpeg($thumb);
  18. ?>
Copy code


php


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