PHP简单生成缩略图相册的方法

yipeiwu_com5年前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禁用函数设置及查看方法详解

本文实例讲述了php禁用函数设置及查看方法。分享给大家供大家参考,具体如下: 打开PHP.INI,找到这行: disable_functions = 在后面那里加上要禁用的函数,如禁用多...

PHP 中文乱码解决办法总结分析

一.首先是PHP网页的编码 1. php文件本身的编码与网页的编码应匹配 a. 如果欲使用gb2312编码,那么php要输出头:header(“Content-Type: text/ht...

php allow_url_include的应用和解释

因为这个原因,许多安全研究人员建议在php.ini配置中禁用指向allow_url_fopen。不幸的是,许多推荐这种方法的人,并没有意识到,这样会破坏很多的应用并且并不能保证100%的...

PHP中list()函数用法实例简析

本文实例讲述了PHP中list()函数用法。分享给大家供大家参考,具体如下: PHP中的list() 函数用于在一次操作中给一组变量赋值。 注意:这里的数组变量只能为数字索引的数组,且假...

php将字符串全部转换成大写或者小写的方法

本文实例讲述了php将字符串全部转换成大写或者小写的方法。分享给大家供大家参考。具体分析如下: php中可以通过strtolower和strtoupper两个函数将字符串中的每个英文字符...