图片相关操作类
class ImageTool
{
private $imagePath ;
private $outputDir ;
public $memoryImg ;
public $path ;
public function __construct ($imagePath , $outputDir = null)
{
$this ->imagePath = $imagePath ;
$this ->outputDir = $outputDir ;
$this ->memoryImg = null ;
$this ->path = null ;
}
public function showImage ()
{
if ($this ->memoryImg != null ) {
$info = getimagesize($this ->imagePath);
$type = image_type_to_extension($info [2 ], false );
header('Content-type:' . $info ['mime' ]);
$funs = "image{$type}" ;
$funs ($this ->memoryImg);
imagedestroy($this ->memoryImg);
$this ->memoryImg = null ;
}
}
private function saveImage ($image )
{
$info = getimagesize($this ->imagePath);
$type = image_type_to_extension($info [2 ], false );
$funs = "image{$type}" ;
if (empty ($this ->outputDir)) {
$funs ($image , md5($this ->imagePath) . '.' . $type );
return md5($this ->imagePath) . '.' . $type ;
} else {
$funs ($image , $this ->outputDir . md5($this