<?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);
????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?imageMark($source,$local,$alpha){
????$info2=getimagesize($source);
????$type2=image_type_to_extension($info2[2],false);
????$fun2="imagecreatefrom{$type2}";
????$water=$fun2($source);
????imagecopymerge($this->image,?$water,?$local['x'],?$local['y'],?0,?0,?$info2[0],?$info2[1],?$alpha);
????imagedestroy($water);
}
//?輸出圖片
public?function?show()?{
????header("Content-type:".$this->info['mime']);
//?????error_reporting(E_ALL^E_NOTICE^E_WARNING);
????$func="image{$this->info['type']}";
????$func($this->image);
}
//?????保存圖片
public?function?save($new){
$func="image{$this->info['type']}";
$func($this->image,$new.'.'.$this->info['type']);
}
//?銷毀圖片
public?function?__destruct()?{
????imagedestroy($this->image);
}
}
?>
<?php
require?"image.class.php";
$src='images/001.jpg';
$source='images/002.jpg';
$content='hello';
$font_url='msyh.ttf';
$size=20;
$color=array(
????0=>255,
????1=>255,
????2=>255,
????3=>20
);
$local=array(
????'x'>=20,
????'y'=>30
);
$alpha=20;
$angle=10;
$image=new?Image($src);
$image->imageMark($source,?$local,?$alpha);
$image->fontMark($content,?$font_url,?$size,?$color,?$local,?$angle);
$image->show();
$image->thumb(300,?150);
$image->save(imageMark);
?>
2017-03-01
$this - > = array() ?這個位置 ,this和-是不是隔得有點遠?
2017-02-19
我也是這樣。。
2017-02-17
我的也是這樣