Adding SourceWidth and SourceHeight to ImageUrlGenerationOptions#14499
Adding SourceWidth and SourceHeight to ImageUrlGenerationOptions#14499JasonElkin merged 6 commits intoumbraco:v17/devfrom
Conversation
|
Hi there @Jeavon, thank you for this contribution! 👍 While we wait for one of the Core Collaborators team to have a look at your work, we wanted to let you know about that we have a checklist for some of the things we will consider during review:
Don't worry if you got something wrong. We like to think of a pull request as the start of a conversation, we're happy to provide guidance on improving your contribution. If you realize that you might want to make some changes then you can do that by adding new commits to the branch you created for this work and pushing new commits. They should then automatically show up as updates to this pull request. Thanks, from your friendly Umbraco GitHub bot 🤖 🙂 |
|
Having to manually provide these dimensions when calling Since the crop URL is generated on the server, the custom
In either case, you still need to have a dependency on ImageSharp to be able to get/populate the image dimensions on the server side though. Maybe an even better solution is to implement this logic directly in Cloudflare (maybe using a custom Worker) or Cloudinary (which already seems to support percentage based crops). Would be awesome to see some cloud-based image processing alternatives for Umbraco, since ImageSharp is now fully decoupled from the CMS and can be completely removed if you want 😄 |
|
@ronaldbarendse I really don't want to have to update all of the GetCropUrl methods either, if you check on the changes I've made in the draft PR, I only changed the string methods as anything with a IPublishedThing can get the source dimensions from the cache. I totally know this would be a breaking change. Given that GetCropUrl can be called a lot in a view, looking up the dimensions from the image file or using the MediaService is going to be really inefficient for a UrlGenerator don't you think (of course it could be a bespoke cached)? It's what lead me to think that this needs to change deeper and therefore adding source dimensions to ImageUrlGenerationOptions might be the best solution and would be useful to any generator... I have a UrlGenerator for both Cloudflare and Cloudinary and unfortunately, the percentage-based cropping on Cloudinary is only accurate to 2 decimals so it doesn't work anywhere near close enough for the Umbraco cropper.
|
|
Hi @Jeavon and @ronaldbarendse This PR seems interesting, but has gone stale? It seems relevant, so could you let me in on what state we are at? |
|
I think the main concerns are:
So it all comes down to whether we want to improve image processing support for these external providers in our own abstraction. On the front-end, you can already use your own implementation, so it's more to ensure the backoffice can get cropped images as well. One workaround that could work on the front-end would be to create new class that inherits from |
|
Hi @Jeavon, do you have any thoughts on Ronalds comment here. Do you agree with his perspectives? Or do you have other perspectives that should be weighted as well? |
|
I still think that the SourceWidth and SourceHeight should be available when implementing a provider one way or another in order to support implementations using any third party providers. These 2 values are available from published cache as they are extracted at upload so it's not necessary to read the file again to find them for this. I have worked around this issue on the front end for my Cloudflare provider by adding these 2 values from published cache onto the querystring so that my IImageUrlGenerator can pick them up (and remove them from the querystring) and use them for it's calculations. It works.... @ronaldbarendse workaround sounds viable to me but I do think that if you implement a provider it should work in the front end and back end really. |
Update README.md with information about the forum Making a small change to the Readme to signpost the Forum now that it's the place to go for help/questions
There was a problem hiding this comment.
Pull Request Overview
This PR adds source image dimensions to the image URL generation process, enabling image processing services like Cloudflare and Cloudinary to properly convert crop coordinates from relative values to absolute pixel values.
Key changes:
- Adds
SourceWidthandSourceHeightproperties toImageUrlGenerationOptions - Updates image cropping extension methods to accept and pass through source dimensions
- Automatically retrieves source dimensions from media items when available
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
ImageUrlGenerationOptions.cs |
Adds nullable SourceWidth and SourceHeight properties to store original image dimensions |
ImageCropperTemplateCoreExtensions.cs |
Updates method signatures to accept source dimensions and passes them to options; retrieves dimensions from media items |
FriendlyImageCropperTemplateExtensions.cs |
Updates extension method signatures to accept and forward source dimensions to core methods |
src/Umbraco.Web.Common/Extensions/FriendlyImageCropperTemplateExtensions.cs
Outdated
Show resolved
Hide resolved
b73b909 to
c9f909e
Compare
…Extensions.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Ahoy @Jeavon, you may have noticed that we've pulled this out of "draft" with a view to including it in v17 🎉 |
…raco#20269) Added skip for the failing smoke test
|
Apologies HQ team for ruining the git history 🥲 |
In order to be able to convert the coordinates provided by a pre-defined crop for various image processing services the source image width and source image height are required. Currently, these values are not available to a ImageUrlGenerator so in this draft PR I'm adding them to ImageUrlGenerationOptions.
For example, this then makes it possible to convert the crop coordinates to use Cloudflare's trim command I need to do the following:
I've also looked at Cloudinary and that would also require the source width and height in order to generate a valid command.
Adding these values to ImageUrlGenerationOptions is one approach to solving this problem, there are others... Open to suggestions....