PHP圖像操作類
PHP圖像操作的一個類,包括給圖像添加文字水印、圖像水印和壓縮圖片。
<?phpclass Image { private $info; private $type; private $iamge; /** * 打開圖片,寫入內存 * **/ public function __construct($src) { $this->info = getimagesize($src); $this->type = image_type_to_extension($this->info[2],false); $fun = "imagecreatefrom".$this->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[0], $this->info[1]); imagedestroy($this->image); $this->image = $image_thumb; } //文字水印 public function fontMark($content, $fontUrl, $size, $color, $locate=array('x'=>0,'y'=>0), $angle=0) { $color = imagecolorallocatealpha($this->image, $color[0], $color[1], $color[2], $color[3]); imagettftext($this->image, $size, $angle, $locate['x'], $locate['y'], $color, $fontUrl, $content); } //圖片水印 public function imageMark($src,$locate,$alpha) { $info2 = getimagesize($src); $type2 = image_type_to_extension($info2[2],false); $fun2 = "imagecreatefrom".$type2; $water = $fun2($src); imagecopymerge($this->image, $water, $locate['x'], $locate['y'], 0, 0, $info2[0], $info2[1], $alpha); imagedestroy($water); } //在瀏覽器中顯示 public function show() { header("Content-type:".$this->info['mime']); $fun = "image".$this->type; $fun($this->image); } //保存為文件 public function save($newname) { $fun = "image".$this->type; $fun($this->image, $newname.'.'.$this->type); } public function __destruct() { imagedestroy($this->image); } } </pre>
本文由用戶 mf72 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!