亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

有錯誤求解答 代碼點開看

<?php

class Image {

/*內存中的圖片*/

private $image;

/*圖片的基本信息*/

private $info;

/*打開一張圖片,讀取到內存中*/

public function __consstruct($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($newimg){

$func = "image{$this->info['type']}";

$func($this->image,image,$newimg.'.'.$this->info['type']);

}

/*銷毀圖片*/

public function __destruct(){

imagedestroy($this->image);

}

}

?>






<?php

require "image_class.php";

$src = '001.png';

$image = new Image('$src');

$image->thumb(300,200);

$image->show();

?>


正在回答

1 回答

http://img1.sycdn.imooc.com//599ff9080001702d03390181.jpg這里出錯了,不用引號

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
GD庫實現圖片水印與縮略圖
  • 參與學習       19005    人
  • 解答問題       168    個

帶你快速高效的完成圖片處理工作,還可以加深對面向對象的理解

進入課程

有錯誤求解答 代碼點開看

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號