While drafting
https://www.scirra.com/labs/specs/imagebitmap-conversion-extensions.html I
realised that there is no way to tell in JS what image formats the browser
can decode (with Image or ImageBitmap objects) or encode (with canvas
toDataURL()/toBlob() or the ImageBitmap.toBlob() method I was proposing).

HTMLMediaElement.canPlayType() can give an indication if an audio or video
format can be decoded. MediaRecorder.canRecordMimeType() can give an
indication if an audio or video format can be encoded. Should we not have
the same for images? For example there are a number of image formats beyond
PNG and JPEG which some browsers support, such as:
- JPEG 2000 (Safari)
- JPEG XR (IE/Edge)
- WebP (Blink)
- APNG (Firefox, Safari)
- any other future formats

Most client-side detection I've seen involves either trying to load a data
URI included in the source, or using canvas' toDataURL() and seeing if the
resulting data URI includes the expected MIME type. I think there should be
methods on some object (be it Image, ImageBitmap or Canvas) for:
- canDecodeType(): indicate if an image format can be encoded by
Image/ImageBitmap objects
- canEncodeType(): indicate if an image format can be encoded by Canvas
toDataURL/toBlob (or my proposed ImageBitmap.toBlob())

Thoughts?

Reply via email to