-
Notifications
You must be signed in to change notification settings - Fork 383
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
Supply the extracted dimensions to images determined to need them #1117
Conversation
@@ -157,30 +157,29 @@ private function determine_dimensions( $need_dimensions ) { | |||
if ( ! $node instanceof DOMElement ) { | |||
continue; | |||
} | |||
$height = $dimensions && isset( $dimensions['height'] ) ? $dimensions['height'] : self::FALLBACK_HEIGHT; | |||
$width = $dimensions && isset( $dimensions['width'] ) ? $dimensions['width'] : self::FALLBACK_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.
I think $this->args['content_max_width']
should be used here if available. It got removed in #979.
$node->setAttribute( 'width', $width ); | ||
$node->setAttribute( 'height', $height ); | ||
$class = $node->hasAttribute( 'class' ) ? $node->getAttribute( 'class' ) . ' amp-wp-unknown-size' : 'amp-wp-unknown-size'; | ||
$node->setAttribute( 'class', $class ); | ||
$node->setAttribute( 'class', trim( $class . ' amp-wp-unknown-size' ) ); |
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.
Is amp-wp-unknown-size
even true here? Shouldn't it only be true if the FALLBACK_HEIGHT
or FALLBACK_WIDTH
are used? Otherwise, if we have $dimensions
then we do know the size.
I'm working on another commit for this. |
* Update image tests to test for normal success case of image dimensions being extracted. * Add test case for when fallback dimensions are provided. * When image has one dimension but lacks another, ensure missing dimensions gets same ratio as underlying image when supplied. * Only add amp-wp-unknown-* classes if the dimensions are actually unknown (and fallbacks are used). * Restore use of content_max_width instead of FALLBACK_WIDTH if defined.
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.
LGTM.
Approved Hi @westonruter, |
* Class AMP_Img_Sanitizer_Test | ||
* | ||
* @covers AMP_Style_Sanitizer | ||
*/ |
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.
Nice addition of DocBlocks 😄
There was a regression introduced in #979 whereby the dimensions determined are no longer actually supplied to the images that need them. Instead, the fallback image sizes are always used.
This issue is most plainly visible in Gutenberg where image blocks do not get output with
width
orheight
.Additionally, this PR ensures that when a
width
orheight
are missing that the missing dimension gets its counterpart supplied based on the ratio of the underlying extracted image dimensions. So given an image that is 1944⨉1191 andpost_content
that contains:✅ This gets converted to:
❌ As opposed to:
Additionally, the
amp-wp-unknown-*
classes will only be provided if the dimensions are actually unknown (and fallbacks are used).This PR also restores use of
content_max_width
if defined instead ofFALLBACK_WIDTH
.