标签:图片处理 empty eric new function public 固定 height style
//缩略图(固定长高容器,等比例缩略图,扩容填充,裁剪) public function thumb($new_width=0,$new_height=0) { if (empty($new_width) && empty($new_height)){ $new_width = $this->width; $new_height = $this->height; } if (!is_numeric($new_width) || !is_numeric($new_width)){ $new_width = $this->width; $new_height = $this->height; } //创建一个容器 $_n_w = $new_width; $_n_h = $new_height; //创建裁剪点 $_cut_width = 0; $_cut_height = 0; //等比例缩略 if ($this->width < $this->height) { $new_width = ($new_height / $this->height) * $this->width; } else { $new_height = ($new_width / $this->width) * $this->height; } if ($new_width < $_n_w) { //如果新高度小于新容器高度 $r = $_n_w / $new_width; //按长度求出等比例因子 $new_width *= $r; //扩展填充后的长度 $new_height *= $r; //扩展填充后的高度 $_cut_height = ($new_height - $_n_h) / 2; //求出裁剪点的高度 } if ($new_height < $_n_h) { //如果新高度小于容器高度 $r = $_n_h / $new_height; //按高度求出等比例因子 $new_width *= $r; //扩展填充后的长度 $new_height *= $r; //扩展填充后的高度 $_cut_width = ($new_width - $_n_w ) / 2; //求出裁剪点的长度 } $this->new = imagecreatetruecolor($_n_w,$_n_h); imagecopyresampled($this->new,$this->img,0,0,$_cut_width,$_cut_height,$new_width,$new_height,$this->width,$this->height); }
标签:图片处理 empty eric new function public 固定 height style
原文地址:http://www.cnblogs.com/by-dxm/p/6286686.html