123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- package imagetype
- var (
- JPEG = RegisterType(&TypeDesc{
- String: "jpeg",
- Ext: ".jpg",
- Mime: "image/jpeg",
- IsVector: false,
- SupportsAlpha: false,
- SupportsColourProfile: true,
- SupportsQuality: true,
- SupportsAnimationLoad: false,
- SupportsAnimationSave: false,
- SupportsThumbnail: false,
- })
- JXL = RegisterType(&TypeDesc{
- String: "jxl",
- Ext: ".jxl",
- Mime: "image/jxl",
- IsVector: false,
- SupportsAlpha: true,
- SupportsColourProfile: true,
- SupportsQuality: true,
- SupportsAnimationLoad: true,
- SupportsAnimationSave: false,
- SupportsThumbnail: false,
- })
- PNG = RegisterType(&TypeDesc{
- String: "png",
- Ext: ".png",
- Mime: "image/png",
- IsVector: false,
- SupportsAlpha: true,
- SupportsColourProfile: true,
- SupportsQuality: false,
- SupportsAnimationLoad: false,
- SupportsAnimationSave: false,
- SupportsThumbnail: false,
- })
- WEBP = RegisterType(&TypeDesc{
- String: "webp",
- Ext: ".webp",
- Mime: "image/webp",
- IsVector: false,
- SupportsAlpha: true,
- SupportsColourProfile: true,
- SupportsQuality: true,
- SupportsAnimationLoad: true,
- SupportsAnimationSave: true,
- SupportsThumbnail: false,
- })
- GIF = RegisterType(&TypeDesc{
- String: "gif",
- Ext: ".gif",
- Mime: "image/gif",
- IsVector: false,
- SupportsAlpha: true,
- SupportsColourProfile: false,
- SupportsQuality: false,
- SupportsAnimationLoad: true,
- SupportsAnimationSave: true,
- SupportsThumbnail: false,
- })
- ICO = RegisterType(&TypeDesc{
- String: "ico",
- Ext: ".ico",
- Mime: "image/x-icon",
- IsVector: false,
- SupportsAlpha: true,
- SupportsColourProfile: false,
- SupportsQuality: false,
- SupportsAnimationLoad: false,
- SupportsAnimationSave: false,
- SupportsThumbnail: false,
- })
- SVG = RegisterType(&TypeDesc{
- String: "svg",
- Ext: ".svg",
- Mime: "image/svg+xml",
- IsVector: true,
- SupportsAlpha: true,
- SupportsColourProfile: false,
- SupportsQuality: false,
- SupportsAnimationLoad: false,
- SupportsAnimationSave: false,
- SupportsThumbnail: false,
- })
- HEIC = RegisterType(&TypeDesc{
- String: "heic",
- Ext: ".heic",
- Mime: "image/heif",
- IsVector: false,
- SupportsAlpha: true,
- SupportsColourProfile: true,
- SupportsQuality: true,
- SupportsAnimationLoad: false,
- SupportsAnimationSave: false,
- SupportsThumbnail: true,
- })
- AVIF = RegisterType(&TypeDesc{
- String: "avif",
- Ext: ".avif",
- Mime: "image/avif",
- IsVector: false,
- SupportsAlpha: true,
- SupportsColourProfile: true,
- SupportsQuality: true,
- SupportsAnimationLoad: false,
- SupportsAnimationSave: false,
- SupportsThumbnail: true,
- })
- BMP = RegisterType(&TypeDesc{
- String: "bmp",
- Ext: ".bmp",
- Mime: "image/bmp",
- IsVector: false,
- SupportsAlpha: true,
- SupportsColourProfile: false,
- SupportsQuality: false,
- SupportsAnimationLoad: false,
- SupportsAnimationSave: false,
- SupportsThumbnail: false,
- })
- TIFF = RegisterType(&TypeDesc{
- String: "tiff",
- Ext: ".tiff",
- Mime: "image/tiff",
- IsVector: false,
- SupportsAlpha: true,
- SupportsColourProfile: true,
- SupportsQuality: true,
- SupportsAnimationLoad: false,
- SupportsAnimationSave: false,
- SupportsThumbnail: false,
- })
- )
- // init registers default magic bytes for common image formats
- func init() {
- // NOTE: we cannot be 100% sure of image type until we fully decode it. This is especially true
- // for "naked" jxl (0xff 0x0a). There is no other way to ensure this is a JXL file, except to fully
- // decode it. Two bytes are too few to reliably identify the format. The same applies to ICO.
- // JPEG magic bytes
- RegisterMagicBytes(JPEG, []byte("\xff\xd8"))
- // JXL magic bytes
- RegisterMagicBytes(JXL, []byte{0xff, 0x0a}) // JXL codestream (can't use string due to 0x0a)
- RegisterMagicBytes(JXL, []byte{0x00, 0x00, 0x00, 0x0C, 0x4A, 0x58, 0x4C, 0x20, 0x0D, 0x0A, 0x87, 0x0A}) // JXL container (has null bytes)
- // PNG magic bytes
- RegisterMagicBytes(PNG, []byte("\x89PNG\r\n\x1a\n"))
- // WEBP magic bytes (RIFF container with WEBP fourcc) - using wildcard for size
- RegisterMagicBytes(WEBP, []byte("RIFF????WEBP"))
- // GIF magic bytes
- RegisterMagicBytes(GIF, []byte("GIF8?a"))
- // ICO magic bytes
- RegisterMagicBytes(ICO, []byte{0, 0, 1, 0}) // ICO (has null bytes)
- // HEIC/HEIF magic bytes with wildcards for size
- RegisterMagicBytes(HEIC, []byte("????ftypheic"),
- []byte("????ftypheix"),
- []byte("????ftyphevc"),
- []byte("????ftypheim"),
- []byte("????ftypheis"),
- []byte("????ftyphevm"),
- []byte("????ftyphevs"),
- []byte("????ftypmif1"))
- // AVIF magic bytes
- RegisterMagicBytes(AVIF, []byte("????ftypavif"))
- // BMP magic bytes
- RegisterMagicBytes(BMP, []byte("BM"))
- // TIFF magic bytes (little-endian and big-endian)
- RegisterMagicBytes(TIFF, []byte("II*\x00"), []byte("MM\x00*")) // Big-Endian, Little-endian
- }
|