Home > php教程 > php手册 > php实现图片缩放功能类

php实现图片缩放功能类

WBOY
Release: 2016-06-13 10:18:46
Original
957 people have browsed it

复制代码 代码如下:


/**
 *  Images类是一个图片处理类
 *  @package application.controllers
 *  @since 1.0
 */
class Images
{

 
 /**
  * 缩放图片
  * @param $source原图片
  * @param $newfile新图片
  * @param $pre缩放比例
  */
 public function thumn($source,$pre,$newfile)
 {
     //获取图片尺寸
  list($s_w,$s_h)=getimagesize($source);
  //生成新的图片尺寸
  $new_w=$s_w*$pre;
  $new_h=$s_h*$pre;

  //创建新的图像
  $new_f=imagecreatetruecolor($new_w, $new_h);
  //用资源图片创建图像
  $sour_f=imagecreatefromjpeg($source);
  //拷贝资源图片到新图像
  imagecopyresampled($new_f, $sour_f, 0, 0, 0, 0, $new_w, $new_h, $s_w, $s_h);
  //输出图片到浏览器
  imagejpeg($new_f,$newfile);

     imagedestroy($new_f);
     imagedestroy($sour_f);
 }
}
 ?>

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template