php实现图片的操作,也就是裁切,跟加水印
<?
class image {
protected $img;
protected $types = array(
1 => 'gif',
2 => 'jpg',
3 => 'png',
6 => 'bmp'
);
public function __construct($img=''){
!$img && $this->param($img);
}
public function param($img){
$this->img = $img;
return $this;
}
public 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;
}
public function thumb($filename,$new_w=160,$new_h=120,$cut=0,$big=0){
$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($old_w < $new_h && $old_h < $new_w && !$big){
return false;
}
if($cut == 0){
$scale = min($new_w/$old_w, $new_h/$old_h);
$width = (int)($old_w*$scale);
$height = (int)($old_h*$scale);
$start_w = $start_h = 0;
$end_w = $old_w;
$end_h = $old_h;
} elseif($cut == 1){
$scale1 = round($new_w/$new_h,2);
$scale2 = round($old_w/$old_h,2);
if($scale1 > $scale2){
$end_h = round($old_w/$scale1,2);
$start_h = ($old_h-$end_h)/2;
$start_w = 0;
$end_w = $old_w;
} else{
$end_w = round($old_h*$scale1,2);
$start_w = ($old_w-$end_w)/2;
$start_h = 0;
&nb
补充:Web开发 , php ,