-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Image block: Consider adding a button to compress the image size. #55106
Comments
More generally, given the capabilities of clients and the distributed processing power they have (vs the hosts) what can we do client-side to make this as performant as possible. |
So, this should be a default compression for all images, or a setting(attribute) in If we go with block level support, it means we should implement this to many more blocks, and also users would have to adjust the quality setting each time, for every block. |
@ntsekouras I see it as a setting per image but not really a persistent attribute, you decide to compress the image which would update the image if already uploaded or pick a compression factor before upload. Developing it as block support is not mandatory IMO |
This sounds like a great idea to me, and it would tremendously help image performance to have it tightly integrated into right the UI where the user is uploading the image. If we want to allow users to tweak the compression level per uploaded image, I would suggest that the value chosen, despite not being persistent on the block, is stored persistently as a user preference (i.e. in WordPress user options) so that the compression level that the user chooses effectively becomes the default/initial state for any subsequent images they upload. |
@jameskoster Designs look good. Do you think this belongs to the "Advanced" section for blocks or should it be more prominent, like a button in the block toolbar or a dedicate section outside "Advanced".? |
FWIW I built a plugin that does this kinda stuff already, using all sorts of WASM stuff. Planning on open sourcing it soon. It could easily be merged into Gutenberg. |
I think there are some more nuances here.
@swissspidy does your plugin handle the above replacement case? I'm curious because you say WASM and I expect some PHP to be there.. |
Don't we have a |
No and in general I think WP REST API only uses |
We do have a "put" (update media) endpoint https://developer.wordpress.org/rest-api/reference/media/#update-a-media-item |
@ntsekouras Yes there‘s also a lot of PHP of course. You don‘t want to override or delete the original image to prevent data loss and in case the user wants to revert the changes. So you need to upload a new one, mark it as compressed/optimized, and add a way to connect/link it with the original. My solution does all that. Let me prepare a demo for you all this week. |
Also worth looking at https://github.com/kleisauke/wasm-vips (maybe that is what @swissspidy's plugin already leverages?) |
It's worth also making sure we say how big the image is, and then we can show the before and after in size and quality. |
So I wasn't planning on making this public until it was more published, but feel free to check out my media experiments repository here: https://github.com/swissspidy/media-experiments The readme contains more information about the things I've built already and what I've planned on adding, like bulk optimization. I should be able to get to that soon though. In the meantime, feel free to reach out to me on Slack if you have any questions. Here are some demo videos: DemosOptimize (compress) an existing image/video optimize-existing-media.movPreferences to select preferred image format etc. Automatic Poster Generation Screen.Recording.2023-10-11.at.20.28.09.movPreview image generation for PDFs Screen.Recording.2023-10-11.at.20.26.38.movConverting GIFs to Videos Screen.Recording.2023-10-11.at.20.31.20.movMute videos by removing audio channel completely Screen.Recording.2023-10-11.at.20.32.24.movRecord yourself via webcam & upload the video Screen.Recording.2023-10-11.at.20.37.07.movImproved media placeholders |
@ntsekouras @swissspidy This is really cool, how do you think we can move forward now? Can we transform this to a Gutenberg PR or something? |
Probably best to start by discussing this more in the #core-editor chat, as there is a lot to unpack and many things to be considered. My plugin barely scratches the surface of what can be done and goes way beyond what has been originally proposed in this issue here. In my experience (I have been working with this kind of stuff for multiple years now), something like compressorjs (which just uses I would love if my plugin ends up in Gutenberg eventually, but it's not quite there yet. I suggest checking it out a bit more closely and giving it a try yourself. |
@swissspidy your plugin seems to do lots of cool stuff 🚀 . Do you think it would be possible to extract something minimal to include in GB and iterate? For example just the image compression without file type conversion etc.. |
I suggest the Advanced panel because it's the only one that exists for all blocks that might use this affordance. This makes the placement consistent across. I'd welcome more thoughts, but if the plan is to have a global default 'quality' setting for all uploaded media, then I don't know that this needs to be more prominent. To me it feels like something you'd generally set-and-forget, and the tool in the Advanced panel caters to the edge cases. It might be useful to have a filterable threshold value, and alert the user somehow (potentially something like #41747) if an image breaches it, similar to the color contrast warnings. Including a preview with size details in the modal (as per @swissspidy's plugin) would be neat. Especially if it can update dynamically as you adjust the quality value. |
Users often have to use online services like https://imagecompressor.com or alternatives to optimize their images. It would be great to explore offering a button (or something like that) right in the image block to compress uploaded images.
We don't need to invent anything, there's a number of libraries that provide compression APIs like https://www.npmjs.com/package/compressorjs
Maybe we could suggest an optimal quality and allow the users to tweak the number to avoid compression quality loss.
The text was updated successfully, but these errors were encountered: