New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 764776 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Last visit > 30 days ago
Closed: Sep 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug

Blocking:
issue 766019



Sign in to add a comment

The effect of setting width and height of HTMLImageElement?

Project Member Reported by zakerinasab@chromium.org, Sep 13 2017

Issue description

Setting 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.
 
2x2.png
1.5 KB View Download
image_size_change.html
549 bytes View Download

Comment 1 by junov@chromium.org, Sep 13 2017

As far as I can tell from reading various bits of the spec, setting the content attributes change the intrinsic size of the <img>, which should be used as 'sw' and 'sh' by drawImage.

This indeed seems like a non-compliance issue.  Before fixing, let's see if there is a compatibility bug by seeing what all other browsers are doing, then decide whether we want to fix this or modify the spec to reflect existing behavior.
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?
image_size_change_img_tag.html
381 bytes View Download
image_size_change_img_tag.png
1.2 KB View Download
IE 11.1593 and Edge 38.14393 produce the same output for both cases.

Comment 4 by f...@opera.com, 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)

Comment 5 by junov@chromium.org, 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.
Blocking: 766019
Status: Fixed (was: Assigned)
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