-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[WIP] Add client-side media processing #64278
base: trunk
Are you sure you want to change the base?
Conversation
9b31a7d
to
1affded
Compare
Size Change: +55.3 kB (+3.12%) Total Size: 1.83 MB
ℹ️ View Unchanged
|
15e88c3
to
903c0d2
Compare
903c0d2
to
0e754c0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huge PR thanks for starting this work. I know it's early and I was not able to review this PR properly, it's too big. But I left some small initial comments.
I was wondering how we can split this PR into smaller chunks. For instance, there are a lot of things that seems like enhancement / code quality / types for existing packages. Maybe we can extract this kind of things easily. Obviously it's a small part of the PR but then we can think about the rest.
@@ -0,0 +1,86 @@ | |||
# `@wordpress/mime` | |||
|
|||
A set of mime type-related helper utilities, wrapping [`mime/lite`](https://www.npmjs.com/package/mime). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need a wrapper package, why not use mime
directly to avoid a new public API / package and maintenance burden.
Mostly asking because the content of the package seems very small.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure I can reuse it directly 👍
|
||
return $response; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think all the endpoint changes can be extracted to a separate PR to ease reviews... We can ping folks working on the REST API to help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure yeah that's possible. It won't be useful on its own, but makes reviewing easier for sure.
$image_size_threshold = (int) apply_filters( 'big_image_size_threshold', 2560, array( 0, 0 ), '', 0 ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound | ||
|
||
$settings['__experimentalAvailableImageSizes'] = gutenberg_get_all_image_sizes(); | ||
$settings['__experimentalBigImageSizeThreshold'] = $image_size_threshold; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you expand a bit on these settings?
I have two thoughs:
- We're trying to move away slowly from block editor settings passed from the server to the client and instead relying more on the endpoints (The base endpoint has been used for similar things)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can look into moving those to the REST API endpoint.
@@ -0,0 +1,138 @@ | |||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that you're using camelCase for file names, we tend to use kebab-case instead.
Anything specific you'd like some visual input on? As a couple of quick tests, I saw very little user-facing changes in this PR. What should we be on the lookout for? |
Note that this PR is still in early stages. The one single user-facing change is in the image block's Advanced panel, where you can compress an existing image. It looks a bit like this: optimize-existing-media.mov |
Nice, thanks. We've some past designs by @jameskoster that are likely relevant for when that piece is ready to be polished: |
Yes I am aware of those (I am also in that thread), so I suppose they're still up-to-date? I have partially implemented it in my plugin, but it works best for multiple attachments (e.g. in a gallery block) and not a single image IMHO (a single image block doesn't have multiple "attachments"). Also, the "Compress original" option though, it has downsides. Anyway, I'll probably iterate on that as part of https://github.com/swissspidy/media-experiments first and remove it from this initial PR for now. So it can be added in a follow-up PR. |
The mockups are up-to-date, yes. I agree the current status is optimized for multiple images, but the same pieces can easily be tweaked to work on a per-image basis, happy to help, feel free to ping @WordPress/gutenberg-design if it becomes more urgent. |
) | ||
: sprintf( | ||
/* translators: %s: file size increase in percent. */ | ||
__( 'The new version is <b>%s bigger</b> :(' ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was testing the PR and this happened to me (33% bigger in 4MB image). When this can happen? It feels weird to click an optimize
button and end up with a bigger file.
Can we handle this differently? At least in the level of wording - ex: see if can be optimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's impossible to say without knowing the image and the settings used. In this PR things like image quality or preferred file format aren't configurable yet either, so depending on the source image a size increase is definitely possible.
I'd suggest trying it again with https://github.com/swissspidy/media-experiments and opening an issue there if it happens, ideally uploading the unmodified original image somewhere too for inspection.
/** | ||
* An isolated orchestrator of store registrations. | ||
*/ | ||
export interface WPDataRegistry { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we need both an interface and a typedef?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC I removed the typedef in favor of the interface here
* | ||
* @param file File object. | ||
*/ | ||
export function validateFileSize( file: File ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this util to get maxUploadFileSize
as a param to avoid the store subscription?
Same question for validateMimeType
function below.
Thanks for starting this! I left just a few comments and will catch up with your other related PRs. It's good that you've started splitting this in smaller chunks to review them easier. |
Thanks @ntsekouras, much appreciated! Once the smaller PRs are reviewed and merged I'll rebase this one here to incorporate all the latest changes from the other repo as well. There's been some great progress all over. |
WORK IN PROGRESS
What?
See #61447 for full context.
This PR lays the foundation for client-side media processing in Gutenberg—meaning we can do things like thumbnail generation, cropping, compression, and format conversion (transcoding) all in the browser. It is heavily inspired by my https://github.com/swissspidy/media-experiments project.
As mentioned in the roadmap at #61447, this first iteration includes the following features:
TODO (for this PR)
block-editor
<->upload-media
integration a bit nicerfetch
be available in unit tests, either in jsdom or native environment 🤔TODO (for later)
Why?
In short:
Check out #61447 and https://github.com/swissspidy/media-experiments for full context.
How?
In a nutshell:
New packages:
@wordpress/media-utils
- is enhanced with new functions, TypeScript, and so on@wordpress/upload-media
- is a new upload queue system powered by@wordpress/data
@wordpress/block-editor
- the exposedmediaUpload
function now adds files to the queue rather than uploading straight to the server.@wordpress/vips
- new dedicated package for interacting with wasm-vips library for all the image processing in a web worker@wordpress/mime
- new dedicated package for dealing with mime types (ext -> mime type and mime type -> ext conversion)Implementation:
wp/v2/media/<id>/sideload
Testing Instructions
There is existing e2e test coverage already for most media-related functionality. However, I plan on porting over more tests from https://github.com/swissspidy/media-experiments which has more extensive coverage, of course also for the new UI elements.
Things to test:
Testing Instructions for Keyboard
The only change relevant for keyboard is the UI for compressing an existing image. Everything else is behind the scenes.
Screenshots or screencast