public function parseType()
    {
        if ( ! $this->type ) {
            $this->stream->resetPointer();

            switch ( $this->stream->read(2) ) {
                case "BM":
                    return $this->type = 'bmp';
                case "GI":
                    return $this->type = 'gif';
                case chr(0xFF) . chr(0xd8):
                    return $this->type = 'jpeg';
                case "\0\0":
                    switch ( $this->readByte($this->stream->peek(1)) ) {
                        case 1:
                            return $this->type = 'ico';
                        case 2:
                            return $this->type = 'cur';
                    }

                    return false;

                case chr(0x89) . 'P':
                    return $this->type = 'png';
                case "RI":
                    if ( substr($this->stream->read(10), 6, 4) == 'WEBP' ) {
                        return $this->type = 'webp';
                    }

                    return false;
                case'8B':
                    return $this->type = 'psd';
                case "II":
                case "MM":
                    return $this->type = 'tiff';
                default:
                    $this->stream->resetPointer();

                    // Keep reading bytes until we find '<svg'.
                    while ( true ) {
                        $byte = $this->stream->read( 1 );
                        if ( '<' === $byte && 'svg' === $this->stream->peek( 3 ) ) {
                            $this->type = 'svg';
                            return $this->type;
                        }
                    }
                    return false;
            }
        }

        return $this->type;
    }
public function parseType()
    {
        if ( ! $this->type ) {
            $this->stream->resetPointer();

            switch ( $this->stream->read(2) ) {
                case "BM":
                    return $this->type = 'bmp';
                case "GI":
                    return $this->type = 'gif';
                case chr(0xFF) . chr(0xd8):
                    return $this->type = 'jpeg';
                case "\0\0":
                    switch ( $this->readByte($this->stream->peek(1)) ) {
                        case 1:
                            return $this->type = 'ico';
                        case 2:
                            return $this->type = 'cur';
                    }

                    return false;

                case chr(0x89) . 'P':
                    return $this->type = 'png';
                case "RI":
                    if ( substr($this->stream->read(10), 6, 4) == 'WEBP' ) {
                        return $this->type = 'webp';
                    }

                    return false;
                case'8B':
                    return $this->type = 'psd';
                case "II":
                case "MM":
                    return $this->type = 'tiff';
                default:
                    $this->stream->resetPointer();

                    // Keep reading bytes until we find '<svg'.
                    while ( true ) {
                        $byte = $this->stream->read( 1 );
                        if ( '<' === $byte && 'svg' === $this->stream->peek( 3 ) ) {
                            $this->type = 'svg';
                            return $this->type;
                        }
                    }
                    return false;
            }
        }

        return $this->type;
    }
public function parseType ( ) { if ( ! $ this -> type ) { $ this -> stream -> resetPointer ( ) ; switch ( $ this -> stream -> read ( 2 ) ) { case "BM" : return $ this -> type = 'bmp' ; case "GI" : return $ this -> type = 'gif' ; case chr ( 0xFF ) . chr ( 0xd8 ) : return $ this -> type = 'jpeg' ; case "\0\0" : switch ( $ this -> readByte ( $ this -> stream -> peek ( 1 ) ) ) { case 1 : return $ this -> type = 'ico' ; case 2 : return $ this -> type = 'cur' ; } return false ; case chr ( 0x89 ) . 'P' : return $ this -> type = 'png' ; case "RI" : if ( substr ( $ this -> stream -> read ( 10 ) , 6 , 4 ) == 'WEBP' ) { return $ this -> type = 'webp' ; } return false ; case '8B' : return $ this -> type = 'psd' ; case "II" : case "MM" : return $ this -> type = 'tiff' ; default : $ this -> stream -> resetPointer ( ) ; // Keep reading bytes until we find '<svg'. while ( true ) { $ byte = $ this -> stream -> read ( 1 ) ; if ( '<' === $ byte && 'svg' === $ this -> stream -> peek ( 3 ) ) { $ this -> type = 'svg' ; return $ this -> type ; } } return false ; } } return $ this -> type ; }
Reads and returns the type of the image

@return bool|string
Reads and returns the type of the image