GetCropUrl with only dimensions is returning a named crop with the given dimensions
I have a strange issue on a site whereby the Image media type Upload property editor has been replaced with the Image Cropper ( Umbraco.ImageCropper) property editor. The datatype is configured with a single named Crop to allow editors to manually select a crop area for images in a certain position on the site.
The problem however is that for images that have the crop set, where they are used elsewhere on the site where they shouldn't be cropped they are still returning the named crop instead of the original image (if that makes sense?).
So, when I am calling @img.GetCropUrl(294, 224) I am actually getting a url like this:
And so as I suspected if there are any crops on the media item but you don't tell it which one you want - it returns the first. I'm not convinced this should be the correct behaviour and would welcome other opinions.
In my mind if I don't give a crop name I want to generate a dynamic crop e.g. one based on the dimensions I provided, not resize and give me the first named crop in the collection.
GetCropUrl with only dimensions is returning a named crop with the given dimensions
I have a strange issue on a site whereby the
Image
media typeUpload
property editor has been replaced with the Image Cropper (Umbraco.ImageCropper
) property editor. The datatype is configured with a single named Crop to allow editors to manually select a crop area for images in a certain position on the site.The problem however is that for images that have the crop set, where they are used elsewhere on the site where they shouldn't be cropped they are still returning the named crop instead of the original image (if that makes sense?).
So, when I am calling
@img.GetCropUrl(294, 224)
I am actually getting a url like this:Whereas I should actually be getting:
Any ideas why this might be and how to work around it without having to create more unwanted crops for what is a huge media library?
This is for a site running v7.6.12.
Thanks, Simon
Hi Simon
Try to use this code:
Hi Alex. I get the same result, the named crop is returned but at the dimensions supplied.
In the directory where the image is there is the following crop.json file content:
...This is not what I would expect to find as none of the values seem to tally up with the crop information in the url.
OK, so I can answer my own question. having dug through the source code I found this;
And so as I suspected if there are any crops on the media item but you don't tell it which one you want - it returns the first. I'm not convinced this should be the correct behaviour and would welcome other opinions.
In my mind if I don't give a crop name I want to generate a dynamic crop e.g. one based on the dimensions I provided, not resize and give me the first named crop in the collection.
Thoughts?
The solution was to write my on UrlHelper Extension method to return my custom crops.
I will probably look to extend this further to make use of focal points but this should suffice for now.
Hi Simon,
Was there ever filed an issue for this?
I'm getting the same behavior in 7.12.x
/Chriztian
Hi Chriztian,
I'm afraid I honestly can't remember but I suspect not, sorry :(
Cheers, Simon
is working on a reply...