2020-02-08 16:49:12 -08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2020-06-09 13:01:05 +10:00
|
|
|
|
using Umbraco.Core;
|
2020-03-24 09:37:46 +01:00
|
|
|
|
using Umbraco.Core.Media;
|
2020-05-20 17:39:07 +02:00
|
|
|
|
using Umbraco.Core.Models;
|
|
|
|
|
|
using Umbraco.Web.Common.Attributes;
|
2020-02-08 16:49:12 -08:00
|
|
|
|
using Umbraco.Web.Models;
|
|
|
|
|
|
using Umbraco.Web.Mvc;
|
|
|
|
|
|
|
2020-06-03 17:17:30 +02:00
|
|
|
|
namespace Umbraco.Web.BackOffice.Controllers
|
2020-02-08 16:49:12 -08:00
|
|
|
|
{
|
|
|
|
|
|
/// <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
|
2020-02-09 11:12:29 -08:00
|
|
|
|
/// implementation in use, and so the BackOffice could should not rely on hard-coded string
|
2020-02-08 16:49:12 -08:00
|
|
|
|
/// building to generate correct URLs
|
|
|
|
|
|
/// </para>
|
|
|
|
|
|
/// </remarks>
|
2020-06-09 13:01:05 +10:00
|
|
|
|
[PluginController(Constants.Web.Mvc.BackOfficeApiArea)]
|
2020-02-09 11:12:29 -08:00
|
|
|
|
public class ImageUrlGeneratorController : UmbracoAuthorizedJsonController
|
2020-02-08 16:49:12 -08:00
|
|
|
|
{
|
|
|
|
|
|
private readonly IImageUrlGenerator _imageUrlGenerator;
|
|
|
|
|
|
|
|
|
|
|
|
public ImageUrlGeneratorController(IImageUrlGenerator imageUrlGenerator)
|
|
|
|
|
|
{
|
|
|
|
|
|
_imageUrlGenerator = imageUrlGenerator;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string GetCropUrl(string mediaPath, int? width = null, int? height = null, ImageCropMode? imageCropMode = null, string animationProcessMode = null)
|
|
|
|
|
|
{
|
2020-05-20 17:39:07 +02:00
|
|
|
|
return _imageUrlGenerator.GetImageUrl(new ImageUrlGenerationOptions(mediaPath)
|
|
|
|
|
|
{
|
|
|
|
|
|
Width = width,
|
|
|
|
|
|
Height = height,
|
|
|
|
|
|
ImageCropMode = imageCropMode,
|
|
|
|
|
|
AnimationProcessMode = animationProcessMode
|
|
|
|
|
|
});
|
2020-02-08 16:49:12 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|