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

yipeiwu_com6年前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提交过来的数据生成为txt文件

一共两个文件,具体链接数据库的部分给直接去除了,前台是提交的文字部分,一行一个,在提交后另一个程序文件进行处理,然后按照提交的文件名生成相应的txt 文件,并在txt 文件中加入数据,在...

php的mail函数发送UTF-8编码中文邮件时标题乱码的解决办法

php的mail函数发送UTF-8编码中文邮件时标题乱码的解决办法

最近遇到一个问题,就是在使用php的mail函数发送utf-8编码的中文邮件时标题出现乱码现象,而邮件正文却是正确的。最初以为是页面编码的问题,发现页面编码utf-8没有问题啊,找了半天...

PHP实现将优酷土豆腾讯视频html地址转换成flash swf地址的方法

本文实例讲述了PHP实现将优酷土豆腾讯视频html地址转换成flash swf地址的方法。分享给大家供大家参考,具体如下: 很多用户不知道如何复制flash地址,只能在程序中帮他们替换了...

php中数字、字符与对象判断函数用法实例

本文实例讲述了php中数字、字符与对象判断函数用法。分享给大家供大家参考。具体分析如下: 在php判断数字,字符,对象,数组等包括有参见 is_bool()、is_int()、is_in...

mysq GBKl乱码

我现在有一个sql文件,里面内容是gbk的。我现在显示全是乱码。 就只是用mysql 4.0.26能显示。 用4.1以上的死活都显示不了。头大了。望大家指点指点,感恩不尽。 我...