奶头挺立呻吟高潮av全片,成人试看120秒体验区,性欧美极品v,A片高潮抽搐揉捏奶头视频

php語言

PHP生成圖片縮略圖類示例代碼

時間:2024-07-31 05:14:02 php語言 我要投稿
  • 相關推薦

PHP生成圖片縮略圖類示例代碼

  導語:PHP如何生成圖片縮略圖類?下面是小編給大家提供的代碼示例,大家可以參考閱讀,更多詳情請關注應屆畢業生考試網。

  class App_image_helper {

  protected $imgFileName;

  protected $imgWidth;

  protected $imgHeight;

  protected $imgMime;

  protected $imgResource;

  static  $imgMineList

  = array(

  'jpeg' => 'image/jpeg',

  'gif' => 'image/gif',

  'png' => 'image/png',

  'wbmp' => 'image/wbmp',

  );

  /**

  * 根據文件名,初始化圖片,

  * 計算出給定圖片的寬、高、圖片類型,并獲取圖片的資源保存到內存,便于下次使用

  * App_image_helper constructor.

  *

  * @param $fileName

  */

  public function __construct($fileName) {

  $this->imgFileName = $fileName;

  list($this->imgWidth, $this->imgHeight, $this->imgMime) = $this->getImageInfo($this->imgFileName);

  $this->imgResource = $this->getImageResource($this->imgFileName);

  }

  /**

  * 根據圖片路徑獲取相關寬、高、MIME類型信息

  *

  * @param $fileName

  *

  * @return array|null

  */

  protected function getImageInfo($fileName) {

  $result = null;

  if ( is_file($fileName) ) {

  $tmpImageInfo = getimagesize($fileName);

  if ( $tmpImageInfo ) {

  $result = array($tmpImageInfo[0], $tmpImageInfo[1], $tmpImageInfo['mime']);

  }

  }

  return $result;

  }

  /**

  * 將圖片文件轉為資源類類型

  *

  * @param $fileName

  *

  * @return null|resource

  */

  protected function getImageResource($fileName) {

  $image = null;

  if ( is_file($fileName) ) {

  switch ($this->imgMime) {

  case self::$imgMineList['jpeg']:

  $image = imagecreatefromjpeg($fileName);

  break;

  case self::$imgMineList['gif']:

  $image = imagecreatefromgif($fileName);

  break;

  case self::$imgMineList['png']:

  $image = imagecreatefrompng($fileName);

  break;

  case self::$imgMineList['wbmp']:

  $image = imagecreatefromwbmp($fileName);

  break;

  default:

  break;

  }

  }

  return $image;

  }

  /**

  * 可根據固定寬,等比縮放圖片;或根據百分比,等比縮放圖片

  *

  * @param int $width

  * @param int $percent

  *

  * @return array|null

  */

  protected function getSizeByScale($width = 360, $percent = 1) {

  $result = null;

  if ( $this->imgWidth && $this->imgHeight ) {

  if ( $width ) {

  $result = array($width, intval($width * $this->imgHeight / $this->imgWidth));

  } elseif ( $percent ) {

  $result = array(intval($this->imgWidth * $percent), intval($this->imgHeight * $percent));

  }

  }

  return $result;

  }

  /**

  * 外調

  *

  * @param int $percentOrWidth int整數表示圖片縮放為固定寬度,0.0~0.99999表示縮放百分比

  * @param null $fileName

  * @param int $quality

  * @param bool $reSample    重新采樣圖片,默認是

  *

  * @return bool

  */

  public function createImage($percentOrWidth = 1, $fileName = null, $quality = 75, $reSample = true) {

  $result = false;

  $fileName ? header('Content-Type: ' . $this->imgMime) : false;

  $size = $this->getSizeByScale(($percentOrWidth <= 1) ? null : $percentOrWidth, $percentOrWidth);

  if ( $size ) {

  $thumb = imagecreatetruecolor($size[0], $size[1]);

  if ( $reSample ) {

  imagecopyresampled($thumb, $this->imgResource, 0, 0, 0, 0, $size[0], $size[1], $this->imgWidth, $this->imgHeight);

  } else {

  imagecopyresized($thumb, $this->imgResource, 0, 0, 0, 0, $size[0], $size[1], $this->imgWidth, $this->imgHeight);

  }

  $result = imagejpeg($thumb, $fileName, $quality);

  }

  return $result;

  }

  }

【PHP生成圖片縮略圖類示例代碼】相關文章:

php生成圖片縮略圖的方法08-23

PHP生成縮略圖的類的方法07-11

php生成縮略圖的兩種方法(代碼)08-08

如何利用PHP代碼在網頁上生成圖片10-12

php生成高清縮略圖實例08-12

php動態生成JavaScript代碼10-03

php自動生成sitemap地圖代碼10-21

php自動生成sitemap地圖的代碼07-31

php生成縮略圖的兩種方法05-24

php生成動態圖片驗證碼的一段代碼04-30

主站蜘蛛池模板: 聊城市| 北流市| 禹城市| 密云县| 贞丰县| 南郑县| 平罗县| 靖边县| 锡林浩特市| 许昌市| 米脂县| 乌审旗| 宿迁市| 巴东县| 翁源县| 清镇市| 昭通市| 拉孜县| 白玉县| 定州市| 额尔古纳市| 扶余县| 乌拉特中旗| 永春县| 汝城县| 南昌市| 青田县| 海伦市| 新晃| 平南县| 恩施市| 红桥区| 察隅县| 蓬安县| 饶河县| 玉田县| 邓州市| 越西县| 磐石市| 武宣县| 阿克陶县|