Home  >  Article  >  Backend Development  >  PHP gets image details (width, height, format, size)

PHP gets image details (width, height, format, size)

WBOY
WBOYOriginal
2016-07-25 08:44:301350browse
  1. function getImageInfo($img) //$img为图像文件绝对路径
  2. {
  3. $img_info = getimagesize($img);
  4. switch ($img_info[2]) {
  5. case 1:
  6. $imgtype = "GIF";
  7. break;
  8. case 2:
  9. $imgtype = "JPG";
  10. break;
  11. case 3:
  12. $imgtype = "PNG";
  13. break;
  14. }
  15. $img_type = $imgtype . "图像";
  16. $img_size = ceil(filesize($img) / 1000) . "k"; //获取文件大小
  17. $new_img_info = array(
  18. "width" => $img_info[0],
  19. "height" => $img_info[1],
  20. "type" => $img_type,
  21. "size" => $img_size
  22. );
  23. print " width";
  24. print $img_info[0];
  25. print " height";
  26. print $img_info[1];
  27. print " format";
  28. print $img_type;
  29. print " size";
  30. print $img_size;
  31. print $new_img_info;
  32. }
  33. $img = "/www/htdocs/images/jf.gif";
  34. getImageInfo($img);
  35. ?>
复制代码

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