PHP添加PNG图片背景透明水印

图片相关操作类

class ImageTool
{
   
    private $imagePath;//图片路径
    private $outputDir;//输出文件夹
    public $memoryImg;//内存图像
    public $path;
    public function __construct($imagePath, $outputDir = null)
    {
   
        $this->imagePath = $imagePath;
        $this->outputDir = $outputDir;
        $this->memoryImg = null;
        $this->path = null;

    }

    /**
     * 显示内存中的图片
     * @param $image
     */
    public function showImage()
    {
   
        if ($this->memoryImg != null) {
            $info = getimagesize($this->imagePath);
            $type = image_type_to_extension($info[2], false);
            header('Content-type:' . $info['mime']);
            $funs = "image{$type}";
            $funs($this->memoryImg);
            imagedestroy($this->memoryImg);
            $this->memoryImg = null;
        }
    }

    /**
     * 保存图片
     * @param $image    图片路径
     * @return string
     */
    private function saveImage($image)
    {
   
        $info = getimagesize($this->imagePath);
        $type = image_type_to_extension($info[2], false);
        $funs = "image{$type}";
        if (empty($this->outputDir)) {
            $funs($image, md5($this->imagePath) . '.' . $type);
            return md5($this->imagePath) . '.' . $type;
        } else {
            $funs($image, $this->outputDir . md5($this

你可能感兴趣的:(php,php,图片,函数)