首页 >后端开发 >php教程 >php生成缩略图代码

php生成缩略图代码

WBOY
WBOY原创
2016-07-25 08:45:05805浏览
  1. /**********************
  2. *@filename - path to the image
  3. *@tmpname - temporary path to thumbnail
  4. *@xmax - max width
  5. *@ymax - max height
  6. */
  7. function resize_image($filename, $tmpname, $xmax, $ymax)
  8. {
  9. $ext = explode(".", $filename);
  10. $ext = $ext[count($ext)-1];
  11. if($ext == "jpg" || $ext == "jpeg")
  12. $im = imagecreatefromjpeg($tmpname);
  13. elseif($ext == "png")
  14. $im = imagecreatefrompng($tmpname);
  15. elseif($ext == "gif")
  16. $im = imagecreatefromgif($tmpname);
  17. $x = imagesx($im);
  18. $y = imagesy($im);
  19. if($x return $im;
  20. if($x >= $y) {
  21. $newx = $xmax;
  22. $newy = $newx * $y / $x;
  23. }
  24. else {
  25. $newy = $ymax;
  26. $newx = $x / $y * $newy;
  27. }
  28. $im2 = imagecreatetruecolor($newx, $newy);
  29. imagecopyresized($im2, $im, 0, 0, 0, 0, floor($newx), floor($newy), $x, $y);
  30. return $im2;
  31. }
复制代码

php


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn