当前位置:Gxlcms > PHP教程 > 又一个生成图片缩略图的函数

又一个生成图片缩略图的函数

时间:2021-07-01 10:21:17 帮助过:25人阅读

  1. function photoThumb($p_thumb_file, $p_photo_file, $p_max_size, $p_quality = 75) {

  2. $pic = @imagecreatefromjpeg($p_photo_file);

  3. if ($pic) {

  4. $thumb = @imagecreatetruecolor ($p_max_size, $p_max_size) or die ("Can't create Image!");
  5. $width = imagesx($pic);
  6. $height = imagesy($pic);
  7. if ($width < $height) {
  8. $twidth = $p_max_size;
  9. $theight = $twidth * $height / $width;
  10. imagecopyresized($thumb, $pic, 0, 0, 0, ($height/2)-($width/2), $twidth, $theight, $width, $height);
  11. } else {
  12. $theight = $p_max_size;
  13. $twidth = $theight * $width / $height;
  14. imagecopyresized($thumb, $pic, 0, 0, ($width/2)-($height/2), 0, $twidth, $theight, $width, $height);
  15. }

  16. ImageJPEG ($thumb, $p_thumb_file, $p_quality);

  17. }
  18. }
  19. ?>

人气教程排行