PHP的图片处理类.pdfVIP

  • 3
  • 0
  • 约8.67千字
  • 约 6页
  • 2018-02-19 发布于浙江
  • 举报
PHP的图片处理类

?php /** * 图像处理类 * @author DZG * @example * $imgs=new image($imgFile);p * 裁剪: if(!$imgs-thumb($targetFile,600,500))die(--图像上传失败! );p * 水印: $imgs-water($targetFile,$water,$pos=0,$pct=50); $targetFile 为已经上传到服务器的文件路径 */ class image { // 当前图片 protected $img; // 图像types 对应表 protected $types = array( 1 = gif , 2 = jpg, 3 = png, 6 = bmp ); /** * 初始化图片类 * @param string $img: 原图片路径p */ public function __construct($img){ $this-img = $img; } /** * 获取图片基本信息 * @param String $img: 图片路径p * @return unknown */ protected function getImageInfo($img){ $info = @getimagesize($img); if(isset($this-types[$info[2]])){ $info[ext] = $info[type] = $this-types[$info[2]]; } else{ $info[ext] = $info[type] = jpg; } $info[type] == jpg $info[type] = jpeg; $info[size] = @filesize($img); return $info; } /** * 裁剪图片 * @param String $filename: 图片保存路径p * @param number $new_w : 图片裁剪后宽度p * @param number $new_h: 图片裁剪后高度p * @param number $cut: 图片裁剪方式:p0 = 等比例裁剪;1=居中裁 剪;2=0,0坐标裁剪p * @param boolean $big: 是否允许放大p * @return boolean|String: false| 图片保存路径p */ public function thumb($filename,$new_w=160,$new_h=120,$cut=0,$big=false){ // 获取原图信息 $info = $this-getImageInfo($this-img); if(!empty($info[0])) { $old_w = $info[0]; $old_h = $info[1]; $type = $info[type]; $ext = $info[ext]; unset($info); if(!$big)

文档评论(0)

1亿VIP精品文档

相关文档