Heim  >  Artikel  >  Backend-Entwicklung  >  php 生成缩略图函数代码_PHP教程

php 生成缩略图函数代码_PHP教程

WBOY
WBOYOriginal
2016-07-13 17:40:34743Durchsuche

  1.  /**
  2.  * 生成图片缩略图
  3.  *
  4.  * @param   string  $src    原图地址
  5.  * @param   string  $savePath 缩略图保存地址
  6.  * @param   integer $width  缩略图宽
  7.  * @param   integer $height 缩略图高
  8.  * @return  string  缩略图地址
  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 缩...
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