Skip to content

SunZhiC/DetectImageType

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DetectImageType

Detect image file format from binary data by analyzing magic bytes (file signatures).

Supported Formats

Format Signature
PNG 89 50 4E 47 0D 0A 1A 0A
JPEG FF D8 FF
JPEG2000 00 00 00 0C 6A 50 20 20 or FF 4F FF 51
GIF GIF87a or GIF89a
BMP BM
TIFF II*\0 or MM\0*
ICO 00 00 01 00
ICNS icns
WebP RIFF....WEBP
HEIC/HEIF ftyp box with heic/heix/hevc/mif1 brands
AVIF ftyp box with avif/avis brands
SVG <?xml or <svg prefix

Usage

// From Data
let type = imageData.detectImageType()
print(type)              // .png
print(type.mimeType)     // "image/png"
print(type.fileExtension) // "png"

// From file path
let type = Data.detectImageType(with: "/path/to/image.heic")

// From URL
let type = Data.detectImageType(with: imageURL)

// From bundle resource
if let type = Data.detectImageType(with: "photo.jpg") {
    print(type)
}

Installation

Copy Data+Extension.swift into your project.

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages