-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make createImageBitmap support SVG, but not RenderingContexts #972
Conversation
<code>ImageData</code> object, a <code>CanvasRenderingContext2D</code> object, or another | ||
<code>ImageBitmap</code> object, and returns a promise that is resolved when a new | ||
<code>ImageBitmap</code> is created.</p> | ||
<p>Takes <var>image</var>, which can be an <code>img</code> element, a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add <span>SVG <code>image</code></span> element
here while you're at it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(markup typo in your comment?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
LGTM with that nit. |
This change fixes issue #923 by allowing ImageBitmap objects to be created from SVG source images, as long as the image has an intrinsic size. If the image does not have an intrinsic size, we still reject the promise with an InvalidStateError, as before. This change also removes CanvasRenderingContext2D from ImageBtimapSource, which was an oversight in PR #790. Since there is no longer a concept of a standalone context, this is no longer needed.
New commit with nit addressed. |
Landed as 43ad288. |
Thank you! |
This monkey patch by @Kaiido implies that "SVG image in Blob as source" isn't supported in Chrome yet and this appears to be the case with my own testing. Am I misunderstanding things? Is this tracked as a bug somewhere? It's been 8 years since this was merged. |
Yes, no browser supports it currently, and I believe that at least in Worker scope it's admitted that we'll never have it because that would mean to move the DOM there. For the ones that really want a bitmap version of an svg Blob, it's still possible through the blob: URL + if (blob.type === "image/svg+xml") {
const img = new Image();
img.src = URL.createObjectURL(blob);
await img.decode();
URL.revokeObjectURL(img.src);
return createImageBitmap(img);
} |
This got added in whatwg#972 but never has been implemented since then. Supporting SVG in Workers is a no-go for most implementers as this would mean at least some DOM would need to be available in these contexts.
createImageBitmap does not support this natively but workaround exists: whatwg/html#972 (comment) Signed-off-by: schtrudl <125376055+schtrudl@users.noreply.github.com>
createImageBitmap does not support this natively but workaround exists: whatwg/html#972 (comment) Signed-off-by: schtrudl <125376055+schtrudl@users.noreply.github.com>
createImageBitmap does not support this natively but workaround exists: whatwg/html#972 (comment) Signed-off-by: schtrudl <125376055+schtrudl@users.noreply.github.com>
This change fixes issue #923 by allowing ImageBitmap objects to
be created from SVG source images, as long as the image has an
intrinsic size. If the image does not have an intrinsic size,
we still reject the promise with an InvalidStateError, as before.
This change also removes CanvasRenderingContext2D from
ImageBtimapSource, which was an oversight in PR #790. Since there
is no longer a concept of a standalone context, this is no longer
needed.