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?fontMark($content,$font_url,$size,$color,$local,$angle){
????????$col=imagecolorallocatealpha($this->image,$color[0],$color[1],$color[2],$color[3]);
????????imagettftext($this->image,$size,$angle,$local[x],$local[y],$col,$font_url,$content);
????}
???//在瀏覽器中輸出圖片
???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);
???}
????????????
????}
????
????<?php?
????require?"image.class.php";
????$src='timg.jpg';
????$content="歡迎來到南充農商網";
????$font_url="simsun.ttc";
????$size=20;
??????$color=array(
?????????0?=>?255,
?????????1?=>?255,
?????????2?=>?255,
?????????3?=>?20
?????);
?????$local=array(
????????'x'=>20,
????????'y'=>30
??????);
????$angle=10;
????$image=new?Image($src);
????$image->fontMark($content,$font_url,$size,$color,$local,$angle);
????$image->show();
?>
1 回答

orangewangjie3473319
TA貢獻5條經驗 獲得超2個贊
數組引用加引號,我測試過的
imagettftext($this->image,$size,$angle,$local['x'],$local['y'],$col,$font_url,$content);
- 1 回答
- 0 關注
- 1261 瀏覽
添加回答
舉報
0/150
提交
取消