国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

php按比例生成縮略圖代碼

2024-09-04 11:44:24
字體:
來源:轉載
供稿:網友
  1. <?php 
  2. class My_Lib_simpleimage {  
  3.  var $image;  
  4.  var $image_type;  
  5.  function load($filename) {   
  6.     //$filename 文件的臨時文件名 $_FILES['name']['tmp_name'] 
  7.   $image_info = getimagesize($filename);  
  8.   $this->image_type = $image_info[2];  
  9.   if$this->image_type == IMAGETYPE_JPEG ) {  
  10.   $this->image = imagecreatefromjpeg($filename);  
  11.   } elseif$this->image_type == IMAGETYPE_GIF ) {  
  12.   $this->image = imagecreatefromgif($filename);  
  13.   } elseif$this->image_type == IMAGETYPE_PNG ) {  
  14.   $this->image = imagecreatefrompng($filename);  
  15.   }  
  16.  } 
  17.   
  18.  function save($filename$image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {  
  19.   if$image_type == IMAGETYPE_JPEG ) {  
  20.   imagejpeg($this->image,$filename,$compression);  
  21.   } elseif$image_type == IMAGETYPE_GIF ) {  
  22.   imagegif($this->image,$filename);  
  23.   } elseif$image_type == IMAGETYPE_PNG ) {  
  24.   imagepng($this->image,$filename);  
  25.   }  
  26.   if$permissions != null) {  
  27.   chmod($filename,$permissions);  
  28.   }  
  29.  }  
  30.  function output($image_type=IMAGETYPE_JPEG) {  
  31.   if$image_type == IMAGETYPE_JPEG ) {  
  32.   imagejpeg($this->image);  
  33.   } elseif$image_type == IMAGETYPE_GIF ) {  
  34.   imagegif($this->image);  
  35.   } elseif$image_type == IMAGETYPE_PNG ) {  
  36.   imagepng($this->image);  
  37.   }  
  38.  } //開源代碼Vevb.com 
  39.  function getWidth() {  
  40.   return imagesx($this->image);  
  41.  }  
  42.  function getHeight() {  
  43.   return imagesy($this->image);  
  44.  } 
  45.   
  46.  #設置縮略圖片高度 
  47.  function resizeToHeight($height) {  
  48.   $ratio = $height / $this->getHeight();  
  49.   $width = $this->getWidth() * $ratio;  
  50.   $this->resize($width,$height);  
  51.  }  
  52.  #設置縮略圖片寬度 
  53.  function resizeToWidth($width) {  
  54.   $ratio = $width / $this->getWidth();  
  55.   $height = $this->getheight() * $ratio;  
  56.   $this->resize($width,$height);  
  57.  }  
  58.  function scale($scale) {  
  59.   $width = $this->getWidth() * $scale/100;  
  60.   $height = $this->getheight() * $scale/100;  
  61.   $this->resize($width,$height);  
  62.  }  
  63.  function resize($width,$height) {  
  64.   $new_image = imagecreatetruecolor($width$height);  
  65.   imagecopyresampled($new_image$this->image, 0, 0, 0, 0, $width$height$this->getWidth(), $this->getHeight());  
  66.   $this->image = $new_image;  
  67.  }  
  68. }  
  69. ?> 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 射洪县| 信阳市| 务川| 新泰市| 维西| 玛沁县| 利津县| 武陟县| 宁德市| 双城市| 霍州市| 佳木斯市| 芦山县| 芦溪县| 巴林右旗| 金平| 湖州市| 罗平县| 杨浦区| 凤山市| 观塘区| 沭阳县| 满洲里市| 乾安县| 三河市| 衡东县| 牙克石市| 雷波县| 南靖县| 文昌市| 无锡市| 浦北县| 东安县| 呼图壁县| 微博| 阿鲁科尔沁旗| 泸定县| 青海省| 三江| 双江| 夹江县|