-
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
When uploading, generate both WebP and jpeg format images by default #142
Comments
One important note here: based on #75 (comment) we need to ensure that both the image |
I'm going to work on a PR for the generating images part. |
Good suggestion from @nosilver4u on slack: For example, if you uploaded 'file.jpeg', for images below |
With #143 in mind, if folks use this: |
in spots like the media library or certain functions, we may still want to treat the file matching the uploaded mime type as the "original" file. so even though there is a full size WebP image, if you go to the media editor, it will use the full size jpeg image (assuming you start with a jpeg upload... that would be the original or a file with -scaled appended). |
The property is added to every single image size available, each value inside the properties array is a reference to a different image mime type. If the image size was created as a JPEG version a WebP version would be created, if a WebP version exists a JPEG version would be created instead based on the details from ticket #142 This mechanism would allow extending the sources properties for more additional mime types. The value for each mime type is an associative array with `file` as the only property for now. And the plan is to include more meaningful properties such as `filesize` to a different mime type.
Created a draft version for a |
Adding a link with different alternatives in how the different image mime types should be stored in the database entry for each attachment: Add your comments, suggestions, and feedback. Thanks. |
Hey @mitogh - thank you for working on this! I like the way the new approach puts the image data right inside the existing sizes array. I still wonder about the idea of storing the data right in the sizes array alongside the original data, the big benefit is all internal functionality would work as is. The disadvantage is we would probably break things :) Noting a few places we will need to extend core to use the data from
What other places will we need to integrate with this new data? What other core functions are used to get all the image sub-sizes, or do we need a new one?
I'm going to create follow up tasks for deleting and regenerating missing images based on the new data we will store |
Thanks, @adamsilverstein based on your comments I've decided to explore some other alternatives and end up with a new approach that is a mix of the described approaches but is basically storing the JPEG versions in And because the JPEG is actually backup of the WebP versions this seems like a more solid solution due to this already solves the problem of removal of images due during the removal of an attachment all the backup sizes are removed as well, additionally to this when using this property, third-party plugins like S3 would upload all the backup sizes as well so those would be available. And because the only usage of the JPEG version is via custom places, it seems like a more sensible approach. I'm creating a new PR with these changes for you to take a look at, so you can provide some feedback. |
Adding an update here with the implementation: I'm adding the findings in this document https://docs.google.com/document/d/1nVFhMXacydGce1ZjSvh14MQeKPS26TcQDeIPw0vmuig/edit?usp=sharing to make sure this approach is documented. |
Thanks @adamsilverstein , I'm using the recommended hook However, there might be other cases that we need to cover like when the image is rotated or cropped should we need to support the same backup mechanism for this type of edit. And this hook is not fired in those scenarios so an update would be required to the PR above to take into account those type of modifications to the original image from within the WordPress editor. I'm opening a new issue for this describing the behavior so we can discuss the alternatives here but replicating what core does for the original image on additional mime types seems like the right path here. |
Right - we will probably need to handle these explicitly. |
Quick update on this issue: I have been researching approaches to async image generation and digging into the core cropping behavior.
|
Ready for review: Please take a look at the code above and provide any feedback on the code or the feature itself, give it a try locally and let us know in case something is not working as expected. |
Reopening because support for the retry mechanism still has to be added (already underway in #188). |
Feature Description
Based on the decision in #96 (comment) we need to work on enabling generating both formats by default.
Specifically we need to address:
wp_generate_attachment_metadata
to generate the additional mime type images (some example code from @erikyo).image_editor_output_formats
which would return an array of mime types. By default this would return['image/webp', 'image/jpeg']
.sizes
array (If only one mime type is given, only that type is generated).additional_sizes
array...1b. In addition to generating the new images, we also need to store meta data for new mime type sizes
sizes
arrayadditional mime type sizes we generate should be stored separately, in a key I propose namingadditional_sizes
sources
array inside each sizepicture
elementsizes
sub sizes be WebP by default, which will be the case with['image/webp', 'image/jpeg']
as the default value forimage_editor_output_formats
get_image_tag
orwp_get_attachment_image_src
as a more direct way for developers to specify the mime type they want to use.add_filter( 'image_editor_output_formats', '__return_false' );
would ensure only the uploaded mime type would be use for sub sizes (current WordPress behavior).add_filter( 'image_editor_output_formats', function() { return array( 'image/jpeg', 'image/webp' ); } );
would ensure jpeg and WebP were generated, with jpeg stored insizes
and used as the default output formatadd_filter( 'image_editor_output_formats', function() { return array( 'image/webp' ); } );
would ensure only WebP sub sizes were generated (current behavior of thewebp-uploads
module).Feedback welcome as well as contributions, please let us know what you plan to work on by leaving a comment.
The text was updated successfully, but these errors were encountered: