You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At current time (Deno 2.2.6), calling createImageBitmap with a Blob object that has a empty type would trigger this error:
InvalidStateError: The MIME type of source image is not specified
hint: When you want to get a "Blob" from "fetch", make sure to go through a file server that returns the appropriate content-type response header,
and specify the URL to the file server like "await(await fetch('http://localhost:8000/sample.png').blob()".
Alternatively, if you are reading a local file using 'Deno.readFile' etc.,
set the appropriate MIME type like "new Blob([await Deno.readFile('sample.png')], { type: 'image/png' })".
But browser implementations seem to support automatic detection of image types. There is a demo:
<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><script>// from https://github.com/web-platform-tests/wpt/blob/ea49709e5880c8133249d919c72d67798afc31ec/html/canvas/element/manual/imagebitmap/createImageBitmap-blob-invalidtype.htmlwindow.onload=()=>{// Source: https://commons.wikimedia.org/wiki/File:1x1.png (Public Domain)constIMAGE=atob("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAA"+"ACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=");letbytes=newUint8Array(IMAGE.length);for(leti=0;i<IMAGE.length;i++){bytes[i]=IMAGE.charCodeAt(i);}constoutput=document.getElementById("output");constlog=(msg)=>{output.appendChild(document.createTextNode(msg));output.appendChild(document.createElement("br"));}for(constctypeof["image/png","","text/html","image/jpeg"]){letblob=newBlob([bytes],{type: ctype});window.createImageBitmap(blob).then(img=>{log(`createImageBitmap(blob) with type "${ctype}": width: ${img.width}, height: ${img.height}`);}).catch(e=>{log(`createImageBitmap(blob) with type "${ctype}" failed: ${e}`);});}}</script></head><body><p>Test for <code>createImageBitmap</code> with invalid type.</p><hr><divid="output"></div></body></html>
We can find that for the non-typed Blob, createImageBitmap returns the correct result. I tested on Chrome and Safari on a MacBook, and Firefox and vivaldi on Linux, and they both works.
The WHATWG standard does not mention what to do when the type of Blob is empty1.
Should Deno also support to detect the image type automatically?
Blob
Run these steps in parallel:
...
Apply the image sniffing rules to determine the file format of imageData, with MIME type of image (as given by image's type attribute) giving the official type.
This issue is not duplicate of #25971.
At current time (Deno 2.2.6), calling
createImageBitmap
with aBlob
object that has a emptytype
would trigger this error:But browser implementations seem to support automatic detection of image types. There is a demo:
We can find that for the non-typed
Blob
,createImageBitmap
returns the correct result. I tested on Chrome and Safari on a MacBook, and Firefox and vivaldi on Linux, and they both works.The WHATWG standard does not mention what to do when the
type
ofBlob
is empty1.Should Deno also support to detect the image type automatically?
@Hajime-san @crowlKats @littledivy
Footnotes
https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#dom-createimagebitmap ↩
The text was updated successfully, but these errors were encountered: