文件1 <?php class image{ // 图片信息变量 private $image; // 内存中的图片 private $info; public function _construct($src) { $info=getimagesize($src); $this->info=array( 'width'=>$info[0], 'height'=>$info[1], 'type'=>image_type_to_extension($info[2],false), 'mime'=>$info['mime'] ); $fun="imagecreatefrom{$this->info['type']}"; $this->image=$fun($src); } //change public function thumb($width,$height) { $image_thumb=imagecreatetruecolor($width,$height); imagecopyresampled($image_thumb,$this->image,0,0,0,0,$width,$height,$this->info['width'],$this->info['height']); imagedestroy($this->image); $this->image=$image_thumb; } //display public function show() { ob_clean(); header("Content-type:".$this->$info['mime']); $funs="image{$this->info['type']}"; $funs($this->image); } //save public function save($newname) { $funs="image{$this->info['type']}"; $funs($this->image,$newname.'.'.$this->info['type']); } public function _destruct() { imagedestroy($this->image); } } ?> 文件二 <?php require "image.class.php"; $src='001.jpg'; $image=new Image($src); $image->thumb(300,150); $image->show(); ?>
一瞬儿光