課程
/后端開發(fā)
/PHP
/GD庫實(shí)現(xiàn)圖片水印與縮略圖
下面分別是錯(cuò)誤提示和我的代碼,不知道錯(cuò)在哪了?
2016-09-14
源自:GD庫實(shí)現(xiàn)圖片水印與縮略圖 5-1
正在回答
$src = "001.jpg" 賦值語句后少了個(gè)分號(hào)";"
Ymuyi 提問者
<?php?//test.php require?"image.class.php"; $src?=?"001.jpg"; $image?=?new?Image($src); //壓縮圖片 $image->thumb(300,150); $image->show(); ?> <?php?//image.class.php class?Image{ /** ?*內(nèi)存中的圖片 ?*/ private?$image; /** ?*圖片的基本信息 ?*/ private?$info; /** ?*打開一張圖片,讀取到內(nèi)存中 ?*/ 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?fontMark($content,$font_url,$size,$color,$local,$angle) { $col?=?imagecolorallocatealpha($this->image,$color[0],$color[1],$color[3],$color[4]); imagettftext($this->image,$size,$angle,$local['x'],$local['y'],$col,$font_url,$content); } /** ?*操作圖片(添加圖片水?。? ?*/ ?public?function?imageMark($source,$local,$alpha) { $info_mark?=?getimagesize($source); $type_mark?=?image_type_to_extension($info_mark[2],false); $fun_mark?=?"imagecreatefrom{$type_mark}"; $image_mark?=?$fun_mark($source); imagecopymerge($this->image,$image_mark,$local['x'],$local['y'],0,0,$info_mark[0],$info_mark[1],$alpha); imagedestroy($image_mark); } ? /** ?*在瀏覽器中輸出圖片 ?*/ public?function?show() { ob_clean();//清空(擦掉)輸出緩沖區(qū) 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); } } ?>
goonce
Ymuyi 提問者 回復(fù) goonce
不過,又出現(xiàn)了新問題,就是圖片沒法正常顯示額,如下所示
舉報(bào)
帶你快速高效的完成圖片處理工作,還可以加深對(duì)面向?qū)ο蟮睦斫?/p> 進(jìn)入課程
1 回答( ! ) Parse error: syntax error, unexpected '{' in D:\Program Files (x86)\Demol\image\fontMark.php on line 3
2 回答Parse error: syntax error, unexpected T_PRIVATE in E:\wamp\www\work\GDIMG\image_class.php on line 6
1 回答Parse error: syntax error, unexpected 'header' (T_STRING)
2 回答Call to undefined function image(jpeg)() in E:\demo\imagedeal\suolvtu.php on line 32
3 回答Warning: imagecopyresampled() expects parameter 2 to be resource, null given in E:\demo\test01\image\image.class.php on line 21
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2016-09-14
$src = "001.jpg" 賦值語句后少了個(gè)分號(hào)";"
2016-09-16
2016-09-16
不過,又出現(xiàn)了新問題,就是圖片沒法正常顯示額,如下所示