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通过ksort()函数给关联数组按照键排序的方法

本文实例讲述了php通过ksort()函数给关联数组按照键排序的方法。分享给大家供大家参考。具体分析如下: php通过ksort()函数给关联数组按照键排序,ksort函数按照关联数组的...

PHP添加Xdebug扩展的方法

xdegug是一个很好的php调试扩展,安装方法也很简单,基本和其他的扩展安装方式差不多. 一、下载对应的DLL 下载地址:https://xdebug.org/download.php...

PHP延迟静态绑定示例分享

没怎么用过这个新特性,其实也不算新啦,试试吧,现在静态类的继承很方便了 <?php class A { protected static $def = '123456...

Http 1.1 Etag 与 Last-Modified提高php效率

Http 1.1 Etag 与 Last-Modified提高php效率

在 Blog 盛行的今天,一些 Web 应用需要解析大量的 RSS Feed .如何提高效率是个非常重要的问题.在 MagpieRSS 的 Features 中列举了这样的一条: HT...

PHP静态方法和静态属性及常量属性的区别与介绍

PHP中若使用static关键字来修饰属性、方法,称这些属性、方法为静态属性、静态方法。static关键字声明一个属性或方法是和类相关的,而不是和类的某个特定的实例相关,因此,这类属性或...