Heim >Backend-Entwicklung >PHP-Tutorial >php调整图像尺寸的代码

php调整图像尺寸的代码

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 09:03:11942Durchsuche
  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. }
  32. ?>
复制代码


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn