Setting imageCropMode site wide
# help-with-umbraco
o
Hi, I see imageCropMode default is "Pad". I want to set imageCropMode: ImageCropMode.Crop as default mode for all GetCropUrl() calls. Is there a setting in appsettings or any other configuration available to set default cropmde? Version: Umbraco 13 TIA
m
https://github.com/umbraco/Umbraco-CMS/blob/contrib/src/Umbraco.Web.Common/Extensions/ImageCropperTemplateCoreExtensions.cs#L484
Copy code
ImageCropMode = imageCropMode ?? ImageCropMode.Pad, // Not sure why we default to Pad
Looks like HQ aren't sure why a function called getCropUrl() defaults to pad either 🙂
Could you perhaps make your own
urlHelperExtension
based off https://github.com/umbraco/Umbraco-CMS/blob/contrib/src/Umbraco.Web.Common/Extensions/UrlHelperExtensions.cs.. and set the
imageCropMode
to ImageCropMode.Crop rather than null? And then use your extension namespace?
or another thought.. could you replace the IImageUrlGenerator service
builder.Services.AddSingleton<IImageUrlGenerator, ImageSharpImageUrlGenerator>();
with a modified one that passes again a modified
ImageUrlGenerationOptions
where the default imageCropMode is specified in the Options? maybe...
public ImageCropMode? ImageCropMode { get; set; } = Models.ImageCropMode.Crop;
Not sure if this is the way to go... 🙂 just 🤔 https://github.com/umbraco/Umbraco-CMS/blob/contrib/src/Umbraco.Core/Media/IImageUrlGenerator.cs https://github.com/umbraco/Umbraco-CMS/blob/contrib/src/Umbraco.Core/Models/ImageUrlGenerationOptions.cs#L18
In fact registering your own
ImageSharpImageUrlGenerator
you could just add a check for options.ImageCropMode == null in the GetImageUrl Method? https://github.com/umbraco/Umbraco-CMS/blob/contrib/src/Umbraco.Cms.Imaging.ImageSharp/Media/ImageSharpImageUrlGenerator.cs#L68
o
I use custom code to get image crop urls. I changed my code to add imageCropMode: ImageCropMode.Crop for image cropping part. Thanks Mike.
34 Views