?<?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);?
}
/**
*?操作圖片(壓縮)
*/
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;
}
/**
* 輸出圖片
*/
public?function?show(){
header('Content-type:',$this->info['mime']);
$funs?=?"image{$this->info['type']}";
$funs($this->image);
}
/**
* 把圖片保存在硬盤里
*/
public?function?save($newname){
$funs?=?"image{$this->info['type']}";
$funs($this->image,$newname.'.'.$this->info['type']);
}
/**
*?銷毀圖片
*/
public?function?__destruct(){
imagedestroy($this->image);
}
}
?>
2017-03-24
40行代碼有問題???header('Content-type:',$this->info['mime']);
應該是?header('Content-type:'.$this->info['mime']);
如何還是不行就試試這個