2022-06-20 08:37:17 +02:00
|
|
|
using Umbraco.Cms.Core;
|
2021-08-10 11:23:37 +02:00
|
|
|
using Umbraco.Cms.Core.Media;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Models;
|
|
|
|
|
using Umbraco.Cms.Web.Common.Attributes;
|
2020-02-08 16:49:12 -08:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
namespace Umbraco.Cms.Web.BackOffice.Controllers;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The API controller used for getting URLs for images with parameters
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// <para>
|
|
|
|
|
/// This controller allows for retrieving URLs for processed images, such as resized, cropped,
|
|
|
|
|
/// or otherwise altered. These can be different based on the IImageUrlGenerator
|
|
|
|
|
/// implementation in use, and so the BackOffice could should not rely on hard-coded string
|
|
|
|
|
/// building to generate correct URLs
|
|
|
|
|
/// </para>
|
|
|
|
|
/// </remarks>
|
|
|
|
|
[PluginController(Constants.Web.Mvc.BackOfficeApiArea)]
|
|
|
|
|
public class ImageUrlGeneratorController : UmbracoAuthorizedJsonController
|
2020-02-08 16:49:12 -08:00
|
|
|
{
|
2022-06-20 08:37:17 +02:00
|
|
|
private readonly IImageUrlGenerator _imageUrlGenerator;
|
2020-02-08 16:49:12 -08:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
public ImageUrlGeneratorController(IImageUrlGenerator imageUrlGenerator) => _imageUrlGenerator = imageUrlGenerator;
|
2020-02-08 16:49:12 -08:00
|
|
|
|
2022-06-20 08:37:17 +02:00
|
|
|
public string? GetCropUrl(string mediaPath, int? width = null, int? height = null, ImageCropMode? imageCropMode = null) => _imageUrlGenerator.GetImageUrl(
|
|
|
|
|
new ImageUrlGenerationOptions(mediaPath) { Width = width, Height = height, ImageCropMode = imageCropMode });
|
2020-02-08 16:49:12 -08:00
|
|
|
}
|