-
Notifications
You must be signed in to change notification settings - Fork 107
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
Ensure post meta reflects image mime type #75
Comments
hi @adamsilverstein, I also don't understand why after this filter the "cloned" webp isn't deleted when I delete the image from WordPress media library, even if the attachment metadata array seems correct. I suspect this issue is related to wp_unique_filename() but not sure. https://gist.github.com/erikyo/f0aca6c34fd1d6bc5f73f953bb342a65 |
I think you need to add the new file data to the returned |
yes, my idea is to replace also the "full" size image on the fly with the copy in webp format (so replacing the $meta['file']), since the original jpg was already stored (or can be stored) as "original_image" and since I don't want to show jpg images when I At the time the filter is fired, the image has already been saved (but the resizes are not and the
this is the reason why i add this in my filter
After my filter the image_metadata will look like this:
But after the sub-sizes have been generated it appears that full is a jpg and not a webp. I didn't realise that (and this is the reason why the full webp image wasn't deleted), I'll try to find out why.
edit: the reason why my filter was overridden was because _wp_make_subsizes() saves again the image metadata using the argument $image_meta which comes as it is generated here so doing it so early is not good. Besides this, I discovered a way that is perhaps better for updating the meta of small images:
|
Moving the filter after the image subsizes generation (using wp_generate_attachment_metadata) has fixed the issue and the generated image full size image was deleted but the old "original_image" not 😥. Again, an additional filter (like 'delete_attachment') would be needed to delete the original_image because it does not happen automatically as I expected. The image_meta array actually looks is like this:
|
the original_image would have been deleted if I had written the path correctly. updated the gist now the filter it work as expected (or at least it does in the way I would like it work). Honestly, I would like the original jpg to be used only when I have to regenerate images, when I have to serve it to users I would prefer it to be always webp. |
If you have the right srcset, this should be the case, even if the image src says jpeg, the browser will load the correct webp from the srcset list. I tested mostly with twentytwentytwo, the behavior may be theme dependent |
I created a test for this case: Currently, what I've noticed is that chrome uses the image in src if it fits perfectly in its container or if the images is smaller than that, and this happens also if there is a webp image of the same size of the original in srcset. I'm using canary which is chrome 3 versions ahead and i don't think that will change anytime soon. Tested also in FF, Edge and safari seem to have the same behaviour (in this case, with my blog). https://html.spec.whatwg.org/multipage/images.html#image-request |
Excellent (and disappointing) research @erikyo - I think this means that when outputting the image tag, we need to ensure the One thing we could consider is adjusting the output, so the img src references the large image size instead of the original image. this output change could be behind a separate filter. I am planning to close this issue because the original reason I opened it is essentially resolved... we can continue the conversation on #142
I can confirm that the mime type is correct in the meta data. The issue originally reported in #32 (comment) was likely due to the behavior of the -scaled image being off which I aim to fix in #143. I am closing this issue as resolved for now. |
When uploading jpeg images with the
webp-uploads
module, we use WebP as the default file type for sub sized images. The post meta that lists the image sizes includes a mime-type value; we should ensure that matches the sub sized image mime type.As reported in #32 (comment)
The text was updated successfully, but these errors were encountered: