html icon indicating copy to clipboard operation
html copied to clipboard

"If image's media data has no intrinsic dimensio..."

Open doomdavve opened this issue 10 years ago • 2 comments

https://html.spec.whatwg.org/#images

If image's media data has no intrinsic dimensions (e.g. it's a vector graphic with no specified content size), then return a promise rejected with an InvalidStateError exception and abort these steps.

Could we clarify that a vector graphic with an explicit zero size would be treated as having no intrinsic dimensions?

Example:

<svg width="0" height="0" viewBox="0 0 1 1">

(or just one of them being zero)

Fwiw, the case is a bit similar to the ImageData constructor that says:

If both sw and sh are non-zero, return the new ImageData object. If one or both of sw and sh are zero, then the constructor must throw an IndexSizeError exception instead.

doomdavve avatar Apr 15 '16 09:04 doomdavve

Good point. My first thought after reading this issue was that we should try to be as consistent as possible with how drawImage() handles its sources: https://html.spec.whatwg.org/multipage/scripting.html#check-the-usability-of-the-image-argument

drawImage() would just fail silently in this case, which is not an option with createImageBitmap: the promise must be either resolved or rejected. Since zero-size ImageBitmap objects are not allowed to exist (the object must have bitmap data), rejection is the logical option.

In the case where a crop rectangle is specified, it may make sense to return a transparent black bitmap the size of the crop rect instead of throwing an exception. Any opinions on that?

junov avatar Apr 15 '16 16:04 junov

No strong opinions on the crop rectangle case but if padding usually works (when crop rect is larger than the source), if makes sense to allow it if the image is empty too.

doomdavve avatar Apr 19 '16 08:04 doomdavve