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生成QRcode实例

php生成QRcode实例

本文实例讲述了php生成QRcode实例。是一个非常有用的功能。分享给大家供大家参考。具体如下: 实例演示效果如下图所示: 主要功能代码如下: <?php ini_...

解析PHPExcel使用的常用说明以及把PHPExcel整合进CI框架的介绍

excel的写入与生成操作:复制代码 代码如下:include 'PHPExcel.php';include 'PHPExcel/Writer/Excel2007.php';//或者in...

php与paypal整合方法

我晕,最近这个用paypal付款的功能搞了我2天,还没搞完。郁闷死了。 先做个笔记,把已经搞定的部分写下来,省的以后忘了。 1 注册SandBox账号,并且建立两个虚拟账号,可以选择自动...

PHP封装的验证码工具类定义与用法示例

PHP封装的验证码工具类定义与用法示例

本文实例讲述了PHP封装的验证码工具类定义与用法。分享给大家供大家参考,具体如下: 下面分享的是我自己封装的验证码工具类,在平时的项目中会比较经常用到的工具类,目前封装的这个工具类简易版...

浅谈PHP中的Trait使用方法

浅谈PHP中的Trait使用方法

概述 在PHP中有一种代码复用的技术, 因为单继承的问题, 有些公共方法无法在父类中写出, 而 Trait可以应对这种情况, 它可以定义一些复用的方法, 然后在你需要使用的类中将其引入即...