Home  >  Article  >  Backend Development  >  Another function to generate image thumbnails

Another function to generate image thumbnails

WBOY
WBOYOriginal
2016-07-25 09:07:15863browse
  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. ?>

复制代码



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