-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Adding SourceWidth and SourceHeight to ImageUrlGenerationOptions #14499
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
base: main
Are you sure you want to change the base?
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. |
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....