<?php
/**
* 图片处理,生成缩略图和添加水印图片
* Created by PhpStorm.
* User: andy
* Date: 17-1-3
* Time: 上午11:55
*/
class Image
{
//原图
private $imgPath; //图片地址
private $width; //图片宽度
private $height; //图片高度
private $type; //图片类型
private $img; //图片(图像流)
//缩略图
private $newImg; //缩略图(图像流)
private $newWidth;
private $newHeight;
//水印图路径
private $waterMarkPath;
//输出图像质量,jpg有效
private $quality;
/**
* Image constructor.
* @param string $imagePath 图片路径
* @param string $markPath 水印图片路径
* @param int $new_width 缩略图宽度
* @param int $new_height 缩略图高度
* @param int $quality JPG图片格输出质量
*/
public function __construct(string $imagePath,
string $markPath = null,
int $new_width = null,
int $new_height = null,
int $quality = 75)
{
$this->imgPath = $_SERVER['DOCUMENT_ROOT'] . $imagePath;
$this->waterMarkPath = $markPath;
$this->newWidth = $new_width ? $new_width : $this->width;
$this->newHeight = $new_height ? $new_height : $this->height;
$this->quality = $quality ? $quality : 75;
list($this->width, $this->height, $this->type) = getimagesize($this->imgPath);
$this->img = $this->_loadImg($this->imgPath, $this->type);
//生成缩略图
$this->_thumb();
//添加水印图片
if (!em