爱问知识人 爱问教育 医院库

php生成缩略图经典类_PHP教程

首页

php生成缩略图经典类_PHP教程


        

提交回答
好评回答
  • 2023-03-15 20:30:00
      从国外网站找到的一款php生成缩略图代码,有需要的朋友可以参考一下。 代码如下image_type = $image_info[2];
    if( $this->image_type == IMAGETYPE_JPEG ) {
    $this->image = imagecreatefromjpeg($filename);
    } elseif( $this->image_type == IMAGETYPE_GIF ) {
    $this->image = imagecreatefromgif($filename);
    } elseif( $this->image_type == IMAGETYPE_PNG ) {
    $this->image = imagecreatefrompng($filename);
    }
    }
    function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {
    if( $image_type == IMAGETYPE_JPEG ) {
    imagejpeg($this->image,$filename,$compression);
    } elseif( $image_type == IMAGETYPE_GIF ) {
    imagegif($this->image,$filename);
    } elseif( $image_type == IMAGETYPE_PNG ) {
    imagepng($this->image,$filename);
    }
    if( $permissions != null) {
    chmod($filename,$permissions);
    }
    }
    function output($image_type=IMAGETYPE_JPEG) {
    if( $image_type == IMAGETYPE_JPEG ) {
    imagejpeg($this->image);
    } elseif( $image_type == IMAGETYPE_GIF ) {
    imagegif($this->image);
    } elseif( $image_type == IMAGETYPE_PNG ) {
    imagepng($this->image);
    }
    }
    function getWidth() {
    return imagesx($this->image);
    }
    function getHeight() {
    return imagesy($this->image);
    }
    function resizeToHeight($height) {
    $ratio = $height / $this->getHeight();
    $width = $this->getWidth() * $ratio;
    $this->resize($width,$height);
    }
    function resizeToWidth($width) {
    $ratio = $width / $this->getWidth();
    $height = $this->getheight() * $ratio;
    $this->resize($width,$height);
    }
    function scale($scale) {
    $width = $this->getWidth() * $scale/100;
    $height = $this->getheight() * $scale/100;
    $this->resize($width,$height);
    }
    function resize($width,$height) {
    $new_image = imagecreatetruecolor($width, $height);
    imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
    $this->image = $new_image;
    }
    }
    ?>Usage
    Save the above file as SimpleImage。
      php and take a look at the following examples of how to use the script。The first example below will load a file named picture。
      jpg resize it to 250 pixels wide and 400 pixels high and resave it as picture2。jpg代码如下load('picture。jpg');
    $image->resize(250,400);
    $image->save('picture2。
      jpg');
    ?>If you want to resize to a specifed width but keep the dimensions ratio the same then the script can work out the required height for you, just use the resizeToWidth function代码如下load('picture。
      jpg');
    $image->resizeToWidth(250);
    $image->save('picture2。jpg');
    ?>http://www。bkjia。com/PHPjc/632969。
      htmlwww。bkjia。comtruehttp://www。bkjia。com/PHPjc/632969。htmlTechArticle从国外网站找到的一款php生成缩略图代码,有需要的朋友可以参考一下。 代码如下 ?php /* * File: SimpleImage。
      php * Author: Simon Jarvis * C。

    赵***

    2023-03-15 20:30:00

类似问题

换一换
  • 电脑/网络 相关知识

  • 电脑网络技术
  • 电脑网络

相关推荐

正在加载...
最新资料 推荐信息 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):