Skip to content

Replace the featured image with WebP version when available#18

Closed
mehulkaklotar wants to merge 2 commits intoadamsilverstein:add/webp-uploadsfrom
mehulkaklotar:replace/featured-image-webp
Closed

Replace the featured image with WebP version when available#18
mehulkaklotar wants to merge 2 commits intoadamsilverstein:add/webp-uploadsfrom
mehulkaklotar:replace/featured-image-webp

Conversation

@mehulkaklotar
Copy link
Copy Markdown

@mehulkaklotar mehulkaklotar commented May 23, 2022

Copy link
Copy Markdown
Owner

@adamsilverstein adamsilverstein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

Copy link
Copy Markdown

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mehulkaklotar Looks good!

One higher-level point of feedback though: This implementation works as a first iteration, and it may be good enough to land in core. However, I'm a bit wary about just reusing the existing regular expression logic to replace image URLs, since it is somewhat expensive and should be unnecessary here.

The different in this code (and any calls to wp_get_attachment_image() for that matter is that we can get the correct MIME type URLs right away since we're programmatically outputting the image. The approach to first use the wrong MIME types (e.g. JPEG) and only then replacing them with the correct MIME type (e.g. WebP) therefore feels inefficient to me.

But I realize this would be a more complex effort, and it would rely on more WordPress core functions supporting a MIME type specification - which will only land a bit later.

@adamsilverstein
Copy link
Copy Markdown
Owner

The different in this code (and any calls to wp_get_attachment_image() for that matter is that we can get the correct MIME type URLs right away since we're programmatically outputting the image.

Good point, this is inefficient and we should really be updating these functions to accept a mime_type parameter/attribute directly and outputting the correct image. Let's land this as a first iteration to get the feature complete then remove this bit when we update core functions to use the new approach.

@felixarntz
Copy link
Copy Markdown

@mehulkaklotar @adamsilverstein Could we close this in favor of taking care of this directly in the relevant core functions? We can work on that once the MIME type parameter is available for the post thumbnail functions.

@adamsilverstein adamsilverstein force-pushed the add/webp-uploads branch 2 times, most recently from f5c73f6 to f4033b6 Compare July 12, 2022 21:41
@mehulkaklotar mehulkaklotar deleted the replace/featured-image-webp branch July 20, 2022 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants