-
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
External images: Save to media library #54185
Comments
A feature like this or similar to this would be very benefitial for prototyping within the editor. Popular graphics programs like Figma and Canva allow their graphics to be embedded on sites and updated in the graphics software in real time. For designers it would be a nice feature to be able to iterate on graphics and then commit them at one point to the media library. Could this be done for all image/graphics related blocks (e.g. the upcoming background feature for group blocks) and featured images? I think it would increase the appeal of using WP as the primary design tool or place where you validate the design in a real context. Right now designers have to rebuild pages within their graphic design tool to see the graphics in context, in the future this wouldn't be neccessary if the graphics could be iterated on in real time, and not having to export and re-import final graphics from a design tool into WP manually would also be a big workflow win imo. |
Thank you for filing this bug report, @scruffian! This looks like an excellent approach 👍 One prospective enhancement we may want to consider is having some mechanism of determining whether an image has already been added to the library, to allow for reuse instead of adding multiple copies. This is particularly relevant if the image is being added via a reusable item like a block pattern, which could potentially get used frequently on new posts. Also of note is that this mechanism should work well for theme images too, which have the same limitations. |
Tagging in @WordPress/performance for awareness! |
Gutenberg already allows uploading external images to the media library. Then you would automatically get srcset too. But lazy loading works also for external images, so that‘s irrelevant here. Width & height could be detected automatically by Gutenberg, not that hard to do. In fact, I do have a plugin that already does it. |
I don't think that's the case; at least not by default. From // Images should have source and dimension attributes for the loading optimization attributes to be added.
if ( ! str_contains( $image, ' src="' ) || ! str_contains( $image, ' width="' ) || ! str_contains( $image, ' height="' ) ) {
return $image;
} The |
Could you elaborate on what you mean here, @swissspidy? Even if we can get external images to reliably lazy load (by always adding In my mind, it seems that whether or not an image is lazily loaded, we'll want to fetch the most adequately sized version rather than the potentially massively sized original, so we'll want a Given that we can only provide image resizing for images in the media library, having a simple workflow to move them there seems like a good idea, and I'd go as far as doing it by default as the mockup appears to suggest. |
I did start to look into this but I think we'd need to use something like getimagesize on these images, which I think would probably have negative performance implications. |
We already did this in prepublish, could be reuse/rework that? |
Do you mean that you were looking into adding the attributes when serving? Assuming that there aren't any concerns with markup compatibility, perhaps the This would also mean, however, that if the URL were to change to a different image in the future it could lead to sizing issues. I think that's an acceptable tradeoff, though, given that there is no expectation of control or reliability on external images anyway. |
This looks fantastic! 🙌 Thank you, @ellatrix! |
Lazy loading requires There is no connection to |
@sgomes I meant you get srcset when uploading the external image to the media library.
We already do. In the image block toolbar IIRC. |
Oh, I see, sorry for the misunderstanding!
I am unfamiliar with that feature, and wasn't able to find it in Gutenberg 16.6.0, which appears to have been released yesterday. Is it hidden behind an option that I'm missing? |
That sounds right to me. Preferably the editor should add image width/height to images automatically. I'd argue even for media library images that would be useful (I believe it's not the case today unless they are resized by the user), but especially for external images where getting the dimensions while serving would indeed be a no-go from a performance perspective.
Can you clarify this concern? How would the URL change? If the user changed the image, we would also be able to fetch the dimensions of said new image, or not? |
A complication here is if the author is linking to a URL that returns a random image with differing dimensions: WordPress/performance#49 (comment). Maybe this use case is not common enough to warrant consideration. But to help guard against this, external images should perhaps get |
Nevertheless, I wouldn't necessarily say this is a no-go since there's not really anything different between fetching dimensions of a remote image versus handling oEmbeds. The AMP plugin fetches dimensions of dimensionless images and stores them in transients. Granted, this is not without its own issues, and if they could be fetched up-front client-side in the editor it would be best. |
Sorry, I wasn't very clear 🙂 My concern is similar to the one that @westonruter expressed; if we measure the external image during an initial phase in the editor, and then always serve it with the dimensions we measured at that point in time, then we run the risk of presenting a new image with the old dimensions if the external URL is ever changed to serve a different image (as in the case of random images served on the same URL, like Weston mentioned). I do think that's an acceptable compromise, though; as I see it, it's part of the inherent risk of relying upon external images. |
As of right now, the If the user resizes the image in the editor, the |
The server performance cost of adding width/height is not considerable, but it has limitations such as when using external images, plus another limitation is when using images in e.g. block templates that are part of the theme (and thus not in the media library either), see WordPress/wordpress-develop#5124 for a related performance bug. More foundationally, I think it is a problem that the only way to have width/height attributes in the editor-generated markup is to resize the image. This makes for an awkward fix in the above PR for example, where we would have to add all the |
Right, sorry I wasn't clear. I meant specifically in the case of media library images; I think the status quo (where the attributes are added when serving) is absolutely fine there, because we get all the browser performance benefits without any server performance impact. So while it also would be fine to make For external and theme images, however, it would definitely be beneficial to start adding |
I wasn't aware of that. I think we can close this then? |
Is this working with Google Docs images? I get this errors:
|
Also experiencing this : |
What problem does this address?
When a site use external images, we can't provide the same performance benefits that we can for images hosted by the site. This includes:
What is your proposed solution?
I don't think there is any way to achieve this using external images in a performant way. Instead we should prompt users to make these external images a part of their library when they try to save their content, something like this:
I'm not sure if comic sans is the right design choice here XD
props to @sgomes for the description above!
The text was updated successfully, but these errors were encountered: