src/thinkextend/image/driver/Gd.php
public function open($imgname)
    {
        //检测图像文件
        if (!is_file($imgname)) {
            throw new \Exception('不存在的图像文件');
        }

        //获取图像信息
        $info = getimagesize($imgname);

        //检测图像合法性
        if (false === $info || (IMAGETYPE_GIF === $info[2] && empty($info['bits']))) {
            throw new Exception('非法图像文件');
        }

        //设置图像信息
        $this->info = [
            'width'  => $info[0],
            'height' => $info[1],
            'type'   => image_type_to_extension($info[2], false),
            'mime'   => $info['mime'],
        ];

        //销毁已存在的图像
        empty($this->im) || imagedestroy($this->im);

        //打开图像
        if ('gif' == $this->info['type']) {
            $class     = '\\shenfakuan\\thinkextend\\image\\driver\\Gif';
            $this->gif = new $class($imgname);
            $this->im  = imagecreatefromstring($this->gif->image());
        } else {
            $fun      = "imagecreatefrom{$this->info['type']}";
            $this->im = $fun($imgname);
        }
        return $this;
    }
public function open($imgname)
    {
        //检测图像文件
        if (!is_file($imgname)) {
            throw new \Exception('不存在的图像文件');
        }

        //获取图像信息
        $info = getimagesize($imgname);

        //检测图像合法性
        if (false === $info || (IMAGETYPE_GIF === $info[2] && empty($info['bits']))) {
            throw new Exception('非法图像文件');
        }

        //设置图像信息
        $this->info = [
            'width'  => $info[0],
            'height' => $info[1],
            'type'   => image_type_to_extension($info[2], false),
            'mime'   => $info['mime'],
        ];

        //销毁已存在的图像
        empty($this->im) || imagedestroy($this->im);

        //打开图像
        if ('gif' == $this->info['type']) {
            $class     = '\\shenfakuan\\thinkextend\\image\\driver\\Gif';
            $this->gif = new $class($imgname);
            $this->im  = imagecreatefromstring($this->gif->image());
        } else {
            $fun      = "imagecreatefrom{$this->info['type']}";
            $this->im = $fun($imgname);
        }
        return $this;
    }
打开一张图像

@param  string $imgname 图像路径

@return $this
@throws \Exception