Skip to content
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

Picture element images: Image size issue #1316

Open
mukeshpanchal27 opened this issue Jun 24, 2024 · 3 comments · May be fixed by #1328
Open

Picture element images: Image size issue #1316

mukeshpanchal27 opened this issue Jun 24, 2024 · 3 comments · May be fixed by #1328
Assignees
Labels
[Module] Picture Element Issues for the Picture Element module [Plugin] Modern Image Formats Issues for the Modern Image Formats plugin (formerly WebP Uploads) [Type] Bug An existing feature is broken

Comments

@mukeshpanchal27
Copy link
Member

Bug Description

When using the new Modern Image Formats picture element support, I noticed that the markup didn't account the image sizes that are selected from editor.

Steps to reproduce

  1. Activate the Modern Image Formats plugin and enable picture support from the Media Settings screen.
  2. Add an image block, Select image size to Thumbnail
  3. Preview the page in the front end it load Full size image instead Thumbnail also the sources is missing for thumb size only. The image width and height get selected image values accordingly.

Screenshots

Editor

Screenshot 2024-06-24 at 5 02 02 PM

Frontend:

Screenshot 2024-06-24 at 5 03 26 PM
@mukeshpanchal27 mukeshpanchal27 added [Type] Bug An existing feature is broken [Plugin] Modern Image Formats Issues for the Modern Image Formats plugin (formerly WebP Uploads) [Module] Picture Element Issues for the Picture Element module labels Jun 24, 2024
@westonruter westonruter added this to the webp-uploads n.e.x.t milestone Jun 24, 2024
@imrraaj
Copy link

imrraaj commented Jun 25, 2024

I can pick up this issue, @mukeshpanchal27 @westonruter can you please assign me

@imrraaj
Copy link

imrraaj commented Jun 26, 2024

I am able to reproduce the bug as per the given steps. I have found the cause of the issue. When the image size is set to Thumbnail, it produces a sources array with a single element, which is overlooked.

return $filtered_sources;

One simple workaround I found is that when there is a single element in the sources array, we can add an empty entry so it will be forced to show the source tag in the frontend.

if ( count( $filtered_sources ) === 1 ) {
	$filtered_sources[] = array(
		'url'        => '',
		'descriptor' => '',
		'value'      => '',
         );
}

Output on the frontend:

Screenshot 2024-06-26 at 2 51 06 PM

I wanted to ask if the workaround mentioned is the best approach or if there are better solutions available. I'm open to any suggestions or alternative ideas to address this issue more effectively.

cc: @thelovekesh

@westonruter
Copy link
Member

I think perhaps a better approach would be to change the logic around here:

if ( false === $sizes ) {
continue;
}

if ( false === $image_srcset ) {
continue;
}
$picture_sources .= sprintf(
'<source type="%s" srcset="%s" sizes="%s">',
esc_attr( $image_mime_type ),
esc_attr( $image_srcset ),
esc_attr( $sizes )
);

If the $sizes is false or $image_srcset is empty, then $image_srcset should be set to the modern image format version of the $src.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Module] Picture Element Issues for the Picture Element module [Plugin] Modern Image Formats Issues for the Modern Image Formats plugin (formerly WebP Uploads) [Type] Bug An existing feature is broken
Projects
Status: Definition ✏️
Development

Successfully merging a pull request may close this issue.

3 participants