<?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);
????????????imagecopyresmpled($image_thumb,$this->image,0,0,0,0,$width,$height,$this->info['width'],$this->info['heigt']);
????????????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);
????????}
}
?>
2016-07-27
單詞拼寫錯了 第33行 imagecopyresmpled該換成imagecopyresampled
2016-04-05
imagecopyresampled()