The effect of setting width and height of HTMLImageElement? |
|||
Issue descriptionSetting width and height of HTMLImageElement doesn't change anything in drawImage. Please see the attached sample. The standard says: "These attributes can be set, to change the corresponding content attributes." https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-element I was expecting setting the image size to result in an image resize, but apparently this is not happening. Firefox and Chrome do not resize too (only clip, as in Chromium). This bug(?) affects the expected results in third_party/WebKit/LayoutTests/external/wpt/2dcontext/drawing-images-to-the-canvas/ layout tests.
,
Sep 13 2017
1. The behavior of Firefox and Opera is the same as Chromium. I'll check others. 2. If you set the value of width and height in the img tag, then the image itself is shown properly resized. drawImage uses the original not-resized image. Please see the output and sample code attached. justin@: When you say they "should be used as 'sw' and 'sh' by drawImage", this doesn't mean a resize is necessary. Would you please clarify? What I expect is to have the image resized to new width and height, and from there it should be behaved like the original image on the disk was resized before loading. Do you expect the same behavior or something else?
,
Sep 13 2017
IE 11.1593 and Edge 38.14393 produce the same output for both cases.
,
Sep 13 2017
'width' and 'height' on <img> are presentational hints (presentation attributes), and has no effect on any intrinsic dimension (which are the dimension of the actual image.) As for the general issue, this is fairly clear from the spec: "When a CanvasImageSource object represents an element that is being rendered and that element has been resized, the original image data of the source image must be used, not the image as it is rendered (e.g. width and height attributes on the source element have no effect on how the object is interpreted when rendering the image for CanvasRenderingContext2D APIs)." https://html.spec.whatwg.org/multipage/canvas.html#image-sources-for-2d-rendering-contexts (third paragraph from the end of the section)
,
Sep 16 2017
Thanks fs@, that settles it! zakerinasab@: there is still a bug here, right? I recall you told me that if the width and height were set in the HTML markup, that had an effect on drawImage, which it should not.
,
Sep 18 2017
,
Sep 19 2017
Replying to comment #5: Apparently my statement was not correct. Changing the image dimension in image tag does not affect the drawImage, which is spec compliant behavior. |
|||
►
Sign in to add a comment |
|||
Comment 1 by junov@chromium.org
, Sep 13 2017