課程
/后端開發
/PHP
/GD庫實現圖片水印與縮略圖
老師可以把源碼共享一下出來嗎?看看為什么瀏覽器無法顯示圖片
2015-08-14
源自:GD庫實現圖片水印與縮略圖 5-1
正在回答
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); ? ?}}?>
俠客島的含笑
加了也沒用啊
/* 顯示圖片 */??? public function show(){??????? ob_clean();????//清空(擦掉)輸出緩沖區
???????? header("Content-type:".$this->info['mime']);??????? $funs = "image{$this->info['type']}";??????? $funs($this->image);??? }
怎么解決的?求方法。
怎么解決的?求方法
問題以解決!
舉報
帶你快速高效的完成圖片處理工作,還可以加深對面向對象的理解
3 回答瀏覽器顯示不出來,老師幫看一下
1 回答瀏覽器無法顯示圖片但是可以保存到本地
1 回答瀏覽器顯示不出圖片
1 回答為什么瀏覽器顯示是一片亂碼
1 回答瀏覽器不顯示圖片,出現亂碼,
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2016-12-15
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);
? ?}
}
?>
2016-10-14
加了也沒用啊
2016-08-13
/* 顯示圖片 */
??? public function show(){
??????? ob_clean();????//清空(擦掉)輸出緩沖區
???????? header("Content-type:".$this->info['mime']);
??????? $funs = "image{$this->info['type']}";
??????? $funs($this->image);
??? }
2016-01-25
怎么解決的?求方法。
2015-11-17
怎么解決的?求方法
2015-08-18
問題以解決!