Home > Backend Development > PHP Tutorial > PHP generates thumbnail function code_PHP tutorial

PHP generates thumbnail function code_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 17:40:34
Original
831 people have browsed it

  1.  /**
  2. * Generate image thumbnail
  3. *
  4. * @param string $src Original image address
  5. * @param string $savePath Thumbnail save address
  6. * @param integer $width Thumbnail width
  7. * @param integer $height Thumbnail height
  8. * @return string Thumbnail address
  9. */
  10.  function buildThumb($src, $savePath, $width = 220, $height = 180)
  11.  {
  12.      $arr = getimagesize($src);
  13.      if (!is_array($arr)) {
  14.          return false;
  15.      }
  16.      //1,2,3 分别为gif,jpg,png
  17.      if ($arr[2] > 4) {
  18.          return false;
  19.      }
  20.      $func = imagecreatefrom;
  21.      switch ($arr[2]) {
  22.          case 1  : $func .= gif; break;
  23.          case 2  : $func .= jpeg; break;
  24.          case 3  : $func .= png; break;
  25.          default :  $func .= jpeg;
  26.      }
  27.      $srcIm = $func($src);
  28.      $im    = imagecreatetruecolor($width, $height);
  29.       imagecopyresized($im, $srcIm, 0, 0, 0, 0, $width, $height, $arr[0], $arr[1]);
  30.      imagejpeg($im, $savePath);
  31.      imagedestroy($srcIm);
  32.      imagedestroy($im);
  33.      return true;
  34.  }
  35. ?>


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/486193.htmlTechArticle?php /** * 生成图片缩略图 * * @param string $src 原图地址 * @param string $savePath 缩略图保存地址 * @param integer $width 缩略图宽 * @param integer $height 缩...
source:php.cn
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template