• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 298  文章 - 377  trackbacks - 0
            <2016年11月>
            303112345
            6789101112
            13141516171819
            20212223242526
            27282930123
            45678910

            常用鏈接

            留言簿(34)

            隨筆分類

            隨筆檔案

            文章檔案

            相冊

            收藏夾

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

              1 <?php
              2     /*
              3     ** author 李攀
              4     ** email 1061589921@qq.com
              5     ** 實現移動開發中,多張圖片排列.
              6     */
              7     $file = './234.png';
              8     $Image = new image($file);
              9     $width = $Image->getImageWidth();
             10     $height = $Image->getImageHeight();
             11     //判斷該相片是否長寬相等
             12     if($width != $height){
             13         //不相等則先以最小邊為長度截取圖片中心部分
             14         if($width > $height){
             15             $x = ($width - $height) / 2;
             16             $y = 0;
             17             $width = $height;
             18         }else{
             19             $y = ($height - $width) / 2;
             20             $x = 0;
             21             $height = $width;
             22         }
             23         $Image->crop($file,$width,$height,$x,$y,$file);
             24     }
             25 
             26     //等比例縮放圖片
             27     $dst_w = 100;
             28     $dst_h = 100;
             29     $Image->reduce($file,$dst_w,$dst_h,$file);
             30 ?>
             31 <?php
             32 class image{
             33     private $_width;
             34     private $_height;
             35     private $_type;
             36     //實例化時獲取圖片信息
             37      function __construct($file_url){
             38          $info = getimagesize($file_url);
             39          $this->_width = $info[0];
             40          $this->_height = $info[1];
             41          $type = $info['mime'];
             42          $type = explode('/',$type);
             43          $this->_type = $type[1];
             44      }
             45      //返回圖片類型
             46      public function getImageType(){
             47          return $this->_type;
             48      }
             49      //返回圖片寬度
             50     public function getImageWidth(){
             51         return $this->_width;
             52     }
             53     //返回圖片高度
             54     public function getImageHeight(){
             55         return $this->_height;
             56     }
             57 
             58     /*
             59     **圖片裁剪
             60     ** $tmp_image源文件
             61     ** $dst_w 裁剪后的圖片的寬度
             62     ** $dst_h 裁剪后的圖片的高度
             63     ** $x 在源圖的$x處坐標開始裁剪
             64     ** $y 在源圖的$y處坐標開始裁剪 
             65     */
             66     public function crop($tmp_image,$dst_w,$dst_h,$x,$y,$path){
             67         switch($this->_type){
             68             case 'jpeg':
             69                 $src = imagecreatefromjpeg($tmp_image);
             70                 break;
             71             case 'gif':
             72                 $src = imagecreatefromgif($tmp_image);
             73                 break;
             74             case 'png':
             75                 $src = imagecreatefrompng($tmp_image);
             76                 break;
             77         }
             78 
             79         $dst = imagecreatetruecolor($dst_w,$dst_h);
             80         $color = imagecolorallocate($dst,255,255,255);
             81         imagecolortransparent($dst,$color);
             82         imagefill($dst,0,0,$color);
             83         $bool = imagecopyresampled($dst,$src, 0,0,$x,$y$dst_w,$dst_h,$dst_w,$dst_h);
             84         switch($this->_type){
             85             case 'jpeg':
             86                 imagejpeg($dst,$path,100);
             87                 break;
             88             case 'gif':
             89                 imagegif($dst,$path);
             90                 break;
             91             case 'png':
             92                 imagepng($dst,$path);
             93                 break;
             94         }
             95 
             96         imagedestroy($src);
             97         imagedestroy($dst);
             98         return $bool;
             99     }
            100 
            101     /*
            102     ** 等比例縮放圖片
            103     ** $tmp_image源圖
            104     ** $dst_w 縮放后的圖片寬度
            105     ** $dst_h 縮放后的圖片高度
            106     */
            107     public function reduce($tmp_image,$dst_w,$dst_h,$path){
            108         switch($this->_type){
            109             case 'jpeg':
            110                 $src = imagecreatefromjpeg($tmp_image);
            111                 break;
            112             case 'gif':
            113                 $src = imagecreatefromgif($tmp_image);
            114                 break;
            115             case 'png':
            116                 $src = imagecreatefrompng($tmp_image);
            117                 break;
            118         }
            119         $imagex = imagesx($src);
            120         $imagey = imagesy($src);
            121         $dst = imagecreatetruecolor($dst_w,$dst_h);
            122         $color = imagecolorallocate($dst,255,255,255);
            123         imagecolortransparent($dst,$color);
            124         imagefill($dst,0,0,$color);
            125         $bool = imagecopyresampled($dst,$src,0,0,0,0,$dst_w,$dst_h,$imagex,$imagey);
            126         switch($this->_type){
            127             case 'jpeg':
            128                 imagejpeg($dst,$path,100);
            129                 break;
            130             case 'gif':
            131                 imagegif($dst,$path);
            132                 break;
            133             case 'png':
            134                 imagepng($dst,$path);
            135                 break;
            136         }
            137         imagedestroy($src);
            138         imagedestroy($dst);
            139         return $bool;
            140     }
            141 }
            @import url(http://www.shnenglu.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
            posted on 2016-08-31 11:52 聶文龍 閱讀(344) 評論(0)  編輯 收藏 引用
            亚洲中文字幕无码久久精品1| 伊人久久大香线焦AV综合影院 | 久久福利青草精品资源站免费| 青青青青久久精品国产h久久精品五福影院1421 | 国产午夜精品理论片久久影视| 亚洲AV无码久久| 亚洲精品乱码久久久久66| 一本色道久久HEZYO无码| 亚洲AV无码久久精品色欲| 久久精品国产亚洲αv忘忧草| 久久人人青草97香蕉| 狠狠色丁香久久婷婷综合蜜芽五月| 久久国产高清一区二区三区| 老司机午夜网站国内精品久久久久久久久 | 久久久久国产精品人妻| 精品国产乱码久久久久久呢| 久久久久99这里有精品10| 2021国产精品午夜久久| 蜜桃麻豆WWW久久囤产精品| 久久久久亚洲av成人网人人软件 | 日韩中文久久| 久久久午夜精品福利内容| 99精品国产99久久久久久97| 国产精品久久久久久吹潮| 国内精品久久久久久久久| 一级A毛片免费观看久久精品| 精品一二三区久久aaa片| 久久91精品久久91综合| 色偷偷88欧美精品久久久| 亚洲国产精品久久久天堂| 91精品国产91久久| 亚洲国产日韩综合久久精品| 久久精品国产亚洲AV麻豆网站| 天天爽天天爽天天片a久久网| 久久久久久噜噜精品免费直播| 99久久国产宗和精品1上映 | 9191精品国产免费久久| 亚洲精品乱码久久久久久| 精品久久久久久无码中文字幕 | 亚洲精品无码久久毛片| 国产精品久久国产精麻豆99网站|