php產生縮圖的方法

來源:互聯網
上載者:User
本篇文章主要介紹php產生縮圖的方法,感興趣的朋友參考下,希望對大家有所協助。

PHP上傳圖片、產生縮圖是比較常用到的功能,一般我們會把這些功能寫一個類,方便我們調用。今天發現了一個比較簡單些的PHP產生縮圖函數的代碼,不敢獨享,特此與大家分享。自己使用時候認真看一下,代碼中都有注釋的。

本文執行個體講述了PHP簡單產生縮圖相簿的方法。具體如下:

<?php/* * written by mot * 根目錄下自己建立image thumb目錄 * */class thumb{  private $src;  private $source;  private $s_width;  private $s_height;  private $dest;  private $d_height;  private $d_width;  private $name;  public function thumb($image_path,$rate = 0.5){    $this->src = $image_path;    $this->source = imagecreatefromjpeg($image_path);    $s_size = getimagesize($image_path);    $this->s_height = $s_size[1];    $this->s_width = $s_size[0];    $this->d_height = 100;    $this->d_width = 100;    $this->dest = imagecreate($this->d_width, $this->d_height);    $this->name = explode('.jpg', $image_path);    $this->name = $this->name[0];  }  public function make(){    imagecopyresized($this->dest, $this->source, 0, 0, 0, 0, $this->d_width, $this->d_height,    $this->s_width, $this->s_height);    $thumb = str_replace('image', 'thumb', $this->name.'-thumb.jpg');    imagejpeg($this->dest,$thumb,100);    $img = $thumb;    echo "<a href=$this->src><img src=$img></a>";  }}$hl = opendir(".\\image\\");while(false != $file = readdir($hl)){  if($file == '.' || $file == '..') continue;  $path = '.\\image\\'.$file;  $tmp = new thumb($path,0.3);  $tmp->make();}

總結:以上就是本篇文的全部內容,希望能對大家的學習有所協助。

相關推薦:

php可逆加密的方法及原理

PHP處理會話的10個函數

PHP如何獲得公眾平台關注使用者的基本資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.