pub fn image_type(header: &[u8]) -> ImageResult<ImageType> {
    if header.len() >= 2 {
        if &header[0..2] == b"\x42\x4D" {
            return Ok(ImageType::Bmp);
        } else if header.len() >= 3 && &header[0..3] == b"\xFF\xD8\xFF" {
            return Ok(ImageType::Jpeg);
        } else if header.len() >= 4 && &header[0..4] == b"\x89PNG" {
            return Ok(ImageType::Png);
        } else if header.len() >= 4 && &header[0..4] == b"GIF8" {
            return Ok(ImageType::Gif);
        } else if header.len() >= 4 && (&header[0..4] == b"II\x2A\x00" || &header[0..4] == b"MM\x00\x2A") {
            return Ok(ImageType::Tiff);
        } else if header.len() >= 4 && &header[0..4] == b"8BPS" {
            return Ok(ImageType::Psd);
        } else if header.len() >= 8 && &header[4..8] == b"ftyp" {
            return Ok(ImageType::Heif);
        } else if header.len() >= 12 && &header[0..4] == b"RIFF" && &header[8..12] == b"WEBP" {
            return Ok(ImageType::Webp);
        } else if (header.len() >= 2 && &header[0..2] == b"\xFF\x0A")
            || (header.len() >= 12 && &header[0..12] == b"\x00\x00\x00\x0CJXL \x0D\x0A\x87\x0A")
        {
            return Ok(ImageType::Jxl);
        } else {
            return Err(ImageError::NotSupported);
        }
    }

    Err(std::io::Error::new(std::io::ErrorKind::UnexpectedEof, "Not enough data").into())
}
/// Get the image type from a header
///
/// # Arguments
/// * `header` - The header of the file.
///
/// # Remarks
///
/// This will check the header to determine what image type the data is.
Get the image type from a header
Get the image type from a header
pub fn image_type(header: &[u8]) -> ImageResult<ImageType> {
    if header.len() >= 2 {
        if &header[0..2] == b"\x42\x4D" {
            return Ok(ImageType::Bmp);
        } else if header.len() >= 3 && &header[0..3] == b"\xFF\xD8\xFF" {
            return Ok(ImageType::Jpeg);
        } else if header.len() >= 4 && &header[0..4] == b"\x89PNG" {
            return Ok(ImageType::Png);
        } else if header.len() >= 4 && &header[0..4] == b"GIF8" {
            return Ok(ImageType::Gif);
        } else if header.len() >= 4 && (&header[0..4] == b"II\x2A\x00" || &header[0..4] == b"MM\x00\x2A") {
            return Ok(ImageType::Tiff);
        } else if header.len() >= 4 && &header[0..4] == b"8BPS" {
            return Ok(ImageType::Psd);
        } else if header.len() >= 8 && &header[4..8] == b"ftyp" {
            return Ok(ImageType::Heif);
        } else if header.len() >= 12 && &header[0..4] == b"RIFF" && &header[8..12] == b"WEBP" {
            return Ok(ImageType::Webp);
        } else if (header.len() >= 2 && &header[0..2] == b"\xFF\x0A")
            || (header.len() >= 12 && &header[0..12] == b"\x00\x00\x00\x0CJXL \x0D\x0A\x87\x0A")
        {
            return Ok(ImageType::Jxl);
        } else {
            return Err(ImageError::NotSupported);
        }
    }
    Err(std::io::Error::new(std::io::ErrorKind::UnexpectedEof, "Not enough data").into())
}
pub fn image_type ( header : & [ u8 ] ) -> ImageResult < ImageType > { if header . len ( ) >= 2 { if & header [ 0 .. 2 ] == b" \x42 \x4D " { return Ok ( ImageType :: Bmp ) ; } else if header . len ( ) >= 3 && & header [ 0 .. 3 ] == b" \xFF \xD8 \xFF " { return Ok ( ImageType :: Jpeg ) ; } else if header . len ( ) >= 4 && & header [ 0 .. 4 ] == b" \x89 " { return Ok ( ImageType :: Png ) ; } else if header . len ( ) >= 4 && & header [ 0 .. 4 ] == b" " { return Ok ( ImageType :: Gif ) ; } else if header . len ( ) >= 4 && ( & header [ 0 .. 4 ] == b" \x2A \x00 " || & header [ 0 .. 4 ] == b" \x00 \x2A " ) { return Ok ( ImageType :: Tiff ) ; } else if header . len ( ) >= 4 && & header [ 0 .. 4 ] == b" " { return Ok ( ImageType :: Psd ) ; } else if header . len ( ) >= 8 && & header [ 4 .. 8 ] == b" " { return Ok ( ImageType :: Heif ) ; } else if header . len ( ) >= 12 && & header [ 0 .. 4 ] == b" " && & header [ 8 .. 12 ] == b" " { return Ok ( ImageType :: Webp ) ; } else if ( header . len ( ) >= 2 && & header [ 0 .. 2 ] == b" \xFF \x0A " ) || ( header . len ( ) >= 12 && & header [ 0 .. 12 ] == b" \x00 \x00 \x00 \x0C \x0D \x0A \x87 \x0A " ) { return Ok ( ImageType :: Jxl ) ; } else { return Err ( ImageError :: NotSupported ) ; } } Err ( std :: io :: Error :: new ( std :: io :: ErrorKind :: UnexpectedEof , " " ) . into ( ) ) }
Get the image type from a header
Get the image type from a header
header
&[u8]
header
&[u8]
remarks
This will check the header to determine what image type the data is.
This will check the header to determine what image type the data is .