⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 image.php

📁 a short sketch about linux syntex lines.
💻 PHP
字号:
<?php/*秀影视频点播系统website:http://www.vodcms.com/QQ:24498936MSN:jdzcn_net@hotmail.comVersion:6*/class Easy_Image {	private  $image;	public $dir;	public $basedir;	public $imageresize;	static public $error;	static public $errno;	/*	生成图片缩略图类方法	@param string 文件名称	@param int 生成图片的最大宽度	@param int 生成图片的最大高度	return string 返回生成后的新图片地址	*/	public function  reSize($filename, $width=0, $height=0){		if ( !preg_match('/http:\/\/(.+?)/', $filename) && $this->imageresize === true ){	//非远程图片时			$IO = new Easy_Filesystem($this->dir);			$filename = substr($filename, strlen($this->basedir));			$resizefile = 'upload/resize/'.date('Y/m/d').'/'.$width.'X'.$height.basename($filename);			if (file_exists($this->dir.$resizefile)){	//如果缩略图已经存在				return $this->basedir.$resizefile;			}			if (is_file($this->dir.$filename) && $width>0 && $height>0){	//图片文件存在				list($srcWidth, $srcHeight, $type) = getimagesize($this->dir.$filename);				if ($srcWidth && $srcHeight){					$perX = $width / $srcWidth;	//缩放宽比率					$perY = $height / $srcHeight;	//高度缩放比率					$maxXY = min($perX, $perY);	//去比率最小的值					$targetWidth = $srcWidth * $maxXY;	//目标宽					$targetHeight = $srcHeight * $maxXY;	//目标高					if($targetWidth<$width){						$x=($width-$targetWidth) / 2;					}else{						$x=0;					}					if($targetHeight<$height){						$y=($height-$targetHeight) / 2;					}else{						$y=0;					}					$image1 = imagecreatetruecolor($width, $height);	//建立一个画布					$color = imagecolorallocate($image1, 255, 255, 255);	//填充背景色					imagefill($image1, 0, 0, $color);					$image = self::openImage($this->dir.$filename);	//gif					if (is_resource($image)){						imagecopyresampled($image1, $image, $x, $y, 0, 0, $targetWidth, $targetHeight, $srcWidth, $srcHeight);						$IO->makedir(dirname($resizefile));						imagejpeg($image1, $this->dir.$resizefile, 100);						imagedestroy($image1);						imagedestroy($image);						return  $this->basedir.$resizefile;					}else{						return $filename;					}				}else{					return $filename;				}							}else {				$this->error = ('文件不存在!');				return $filename;			}		}else{			return $filename;		}	}	/*	返回资源对象	*/	private static function openImage($filename){		if (is_file($filename)){			$type = getimagesize($filename);			switch($type[2]){				case 1:					$image = imagecreatefromgif( $filename );	//gif				break;				case 2:					$image = imagecreatefromjpeg( $filename );				break;				case 3:					$image = imagecreatefrompng( $filename );				break;				default:					self::$error = '图片不是允许的类型';					self::$errno = 1;					return false;				break;					}			return $image;		}	}}?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -