国产探花免费观看_亚洲丰满少妇自慰呻吟_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. ?> 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 铜鼓县| 铁力市| 石门县| 钦州市| 洪雅县| 隆子县| 开江县| 手游| 内丘县| 大洼县| 武清区| 石河子市| 延安市| 呈贡县| 梁河县| 德安县| 南昌县| 铁岭市| 蓬莱市| 克拉玛依市| 宿松县| 东乌| 伊宁县| 乌拉特后旗| 上栗县| 丰县| 从化市| 平塘县| 西林县| 保靖县| 汶上县| 漳浦县| 汕尾市| 万州区| 桂林市| 碌曲县| 巍山| 锦屏县| 灵山县| 黑河市| 白河县|