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

Ensure optimized images have correct metadata #237

Closed
swissspidy opened this issue Dec 4, 2023 · 3 comments
Closed

Ensure optimized images have correct metadata #237

swissspidy opened this issue Dec 4, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@swissspidy
Copy link
Owner

swissspidy commented Dec 4, 2023

When optimizing an existing image and converting it to AVIF, some metadata might be missing if the server doesn't natively support the format. _wp_attachment_metadata will only have filesize but nothing else.

width, height, file should be trivial to add. Either copy from original or generate client-side.

This is needed so that the missing_image_sizes logic for client-side thumbnail generation works as expected for AVIF. Right now missing_image_sizes returns an empty array.

@swissspidy swissspidy added the bug Something isn't working label Dec 4, 2023
@swissspidy
Copy link
Owner Author

Copying the data server-side works, but there are PHP warnings because width and height are missing initially when populating missing_image_sizes response field,

So providing client-side might be better.

Alternatively, on rest_after_insert_attachment hook into wp_generate_attachment_metadata to add the missing metadata. That would get rid of the PHP warnings and overall feels a bit cleaner.

swissspidy added a commit that referenced this issue Dec 5, 2023
@swissspidy
Copy link
Owner Author

When optimizing an existing image and converting it to AVIF, [...]

Probably also an issue when uploading an image directly as AVIF? in that case this must be done client-side either way.

Vips or canvas could be used to get image dimensions. After that, send to server via additionalData

@swissspidy
Copy link
Owner Author

I think 068ad7b resolved the last remaining issues here. Closing for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant