-
Notifications
You must be signed in to change notification settings - Fork 382
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
Prevent distortion of images with a 'sizes' attribute #4622
Conversation
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.
All-in with the constants... :)
if ( isset( $new_attributes['sizes'] ) ) { | ||
$new_attributes['disable-inline-width'] = ''; |
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.
You should use Attribute
here.
if ( isset( $new_attributes['sizes'] ) ) { | |
$new_attributes['disable-inline-width'] = ''; | |
if ( isset( $new_attributes[ Attribute::SIZES ] ) ) { | |
$new_attributes[ Attribute::DISABLE_INLINE_WIDTH'] = ''; |
Note: You'll have to add the DISABLE_INLINE_WIDTH
constant to the Layout
class as well.
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.
Constants everywhere 😄!
if ( isset( $new_attributes[ Attribute::SIZES ] ) ) { | ||
$new_attributes[ Attribute::DISABLE_INLINE_WIDTH ] = ''; | ||
} |
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.
Relevant change ⬆️.
As expected, on a page with images, the changes in this PR result in the
This is expected as this regression will then be addressed as part of #4482. |
I'm testing this with the issue in #1939 regarding inline images. In Twenty Nineteen, adding content like so: The non-AMP version and the AMP version on But with this PR there is a regression: This is due to the .i-amphtml-layout-responsive,
[layout=responsive][width][height]:not(.i-amphtml-layout-responsive),
[width][height][sizes]:not(.i-amphtml-layout-responsive)
{
display: block;
position: relative;
} If I'm not mistaken, I think this CSS may actually be not updated for to account for the
I'm checking with the AMP team: ampproject/amphtml#27083 (comment). |
Note this issue did not show up in testing Twenty Twenty because it (erroneously) has a |
The |
Opened a PR to fix the the issue in |
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.
Upstream PR merged: ampproject/amphtml#28020
@schlessera anything else on this PR to receive your ✅? |
I guess not 😄 I'll merge and you can amend as needed in #4482. |
Summary
This PR re-adds the disabled
sizes
attribute to theamp-img
component, and disables the inline width being added by adding thedisable-inline-width
attribute. This should prevent any distortion of the image when viewed with an AMP page.I'm using the post content @westonruter posted in #2036 to test some of the possible ways an image can be used on a page. This verifies that there are no apparent regressions:
Desktop
Mobile
Fixes #4606.
Checklist