-
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
Improve story page background media with image srcset, reduced image size, and a11y text #3006
Improve story page background media with image srcset, reduced image size, and a11y text #3006
Conversation
Supply wp-image-X class name so that srcset is supplied. Also use object-position attribute instead of object-position inline style.
I'm somewhat out of my depth for the /cc @swissspidy |
@@ -134,13 +135,15 @@ class PageEdit extends Component { | |||
mediaType = media.type; | |||
} | |||
|
|||
const mediaUrl = has( media, [ 'sizes', MAX_IMAGE_SIZE_SLUG, 'url' ] ) ? media.sizes[ MAX_IMAGE_SIZE_SLUG ].url : media.url; |
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.
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.
Ah, that makes sense.
@miina Mind taking a look at adding the block deprecation for the changed img tag? |
Sure, checking now. |
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
@googlebot I consent. |
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
Added the deprecation,
will check that, too, to be able to test the deprecation better. |
Hi @westonruter,
Good question. I think the elseif block that unsets the full image may still be relevant, but the first if block probably isn't. 1. First
|
if ( isset( $_POST['action'] ) && ( 'query-attachments' === $_POST['action'] || 'upload-attachment' === $_POST['action'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
$image_sizes[ self::MAX_IMAGE_SIZE_SLUG ] = $full_size_name; |
^ This probably isn't needed anymore. It had 2 purposes:
a) On clicking 'Background Media' > 'Select Media' and uploading an image, it adds self:: MAX_IMAGE_SIZE_SLUG
to the available image sizes
b) In the Image block, on clicking 'Media Library,' it adds the self:: MAX_IMAGE_SIZE_SLUG
to the available image sizes in the Media Library
But removing that if
block doesn't seem to have an effect. Like you mentioned, in this PR the Background Media doesn't look at media.sizes
, it uses the media.url
.
2. elseif block
amp-wp/includes/class-amp-story-media.php
Lines 225 to 228 in f17f597
} elseif ( get_post_type() && AMP_Story_Post_Type::POST_TYPE_SLUG === get_post_type() ) { | |
$image_sizes[ self::MAX_IMAGE_SIZE_SLUG ] = $full_size_name; | |
unset( $image_sizes['full'] ); | |
} |
Deleting this conditional did have an effect, and I'm not sure if it'd be good to delete it now.
To recap what it does, in the Image block's 'Image Size' <select>
, it removes the 'Full Size', and adds 'Story Max Size':
Without that code above, a user can select a full size image. And it looks like the srcset
doesn't reduce the image size enough.
Though the user would have to select the full size image, large is still the default.
For example:
- Checkout this PR's branch and delete this line:
amp-wp/includes/class-amp-story-media.php
Line 99 in f17f597
add_filter( 'image_size_names_choose', [ __CLASS__, 'add_new_max_image_size' ] ); - Create an Image block
- Click 'Media Library'
- Upload a 4000 x 4000 image
- In the 'Image Size'
<select>
, choose 'Full Size' - Publish the story, and go to the front-end
- Expected: the
srcset
produces acurrentSrc
at least a little smaller than the full4000 x 4000
size - Actual: the
currentSrc
is4000 x 4000
This seems to be the case even with smaller image sizes, like 2000 x 2000.
With this PR's branch as is, without deleting that line, it's a little better:
@kienstra Thanks a lot for the thorough response. I did some testing as well and it turns out that when doing device emulation (simulating Pixel 2, for example) the |
I think we can defer adding a new image size for desktop for a future release. |
@miina Could you resolve the conflicts with the templates? |
Humm, E2E failures? |
Hmph, there's a test that doesn't pass reliably, will restart the tests, should look into improving this test again. Thought that it got fixed already but apparently not. |
Or actually, this time it looks like it's another test. Looking into this now. |
A different test is failing every time. Hard to debug as well since locally not failing. It might be related to the issue in this version of Puppeteer that
The upstream helpers use the |
Looking at the tests now ( |
Skipped that flaky test for now; can be investigated separately. |
Will look into that CTA test. |
Opened Jetpack PR to reduce Photon-sized images from 1440px to 1280px: Automattic/jetpack#13278 |
* tag '1.2.1': (434 commits) Bump 1.2.1 Adjust block inserter style. (#3075) Update dependency eslint-plugin-jest to v22.15.2 Fix flaky CTA test (#3057) Add more resizing handles (#3023) Bump version to 1.2.1-RC1 Improve story page background media with image srcset, reduced image size, and a11y text (#3006) Wait until content loaded before calculating font size. (#3052) Harden logic for normalizing image metadata before adding story images (#3049) Update dependency uuid to v3.3.3 (#3046) Inline color support (#3033) Update dependency webpack-cli to v3.3.7 (#3040) Tiny prop-types fix Update dependency babel-jest to v24.9.0 (#3037) Update e2e test setup (#3031) Include amp-script among dynamic_element_selectors in tree shaking Another try to fix tests. Ensure selecting the first page before removing the block. Move setting input selection to the end to helpers. Fix editor test. ...
Fixes #2835. Revisits #2332, #2509.
amp_story_page
image size to 1280px high instead of 1440px high.amp-img
for theamp-story-page
background image element, this PR adds animg
similar to how thecore/image
block does, including the importantwp-image-{attachment_id}
class. This ensures thatwp_make_content_images_responsive()
is able to supply asrcset
for the image (whereas currently there is none), potentially allowing reduced bandwidth when more appropriate image sizes are available; this allows for plugins like Jetpack to supply dynamically-generated image sizes. The image sanitizer converts theimg
to anamp-img
. The inclusion ofsrcset
also means this logic can be replaced with justconst mediaUrl = media.url
:amp-wp/assets/src/stories-editor/blocks/amp-story-page/edit.js
Line 137 in 186c83e
alt
attribute to the background image, and anaria-label
to the background video.object-position
attribute instead of theobject-position
style. This reduces the amount of CSS includedstyle[amp-custom]
and avoids the opaqueamp-wp-...
class name.Still needing to be done:
1800px
-tall image size for desktop stories?\AMP_Story_Media::add_new_max_image_size()
? See c330ce7.Rendered Output Before
Rendered Output After