PHP簡單生成縮略圖相冊的方法
更新時間:2015年07月29日 09:41:57 作者:吳家耀
這篇文章主要介紹了PHP簡單生成縮略圖相冊的方法,實例分析了php生成縮略圖的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了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程序設(shè)計有所幫助。
相關(guān)文章
PHP ajax跨子域的解決方案之document.domain+iframe實例分析
這篇文章主要介紹了PHP ajax跨子域的解決方案之document.domain+iframe,結(jié)合實例形式分析了PHP ajax跨子域的解決方案document.domain+iframe的基本原理、實現(xiàn)方法與操作注意事項,需要的朋友可以參考下2020-03-03
PHP學(xué)習筆記之三 數(shù)據(jù)庫基本操作
本文介紹最基本最實用的數(shù)據(jù)庫操作。首先簡單復(fù)習下MySQL的使用方法,并且建好一張表備用。MySQL在Linux系統(tǒng)上一般都是裝好的,在win下安裝也很簡單,不多做介紹。2011-01-01

