Reputation: 403
I am using ImageGen on Umbraco v7.1. So far so good and am able to get crop urls through my Razor code.
However, I need to get the crop url on my Api controller but am unsure how to do this.
This is how I am currently trying to get it.
ModelImage = Services.MediaService.GetById(galleryId).GetValue("modelImage").ToString()
...where ModelImage
is an alias for the "Image Cropper" datatype.
This returns the image url in the src property along with crop information (line breaks added):
ModelImage: "{
"focalPoint": {
"left": 0.5,
"top": 0.5
},
"src": "/media/1828/bob-marley-thumbnail-update.jpg",
"crops": [
{
"alias": "modelListCrop",
"width": 298,
"height": 380,
"coordinates": {
"x1": 0.071221447830289469,
"y1": .051177864855964005,
"x2": 0.42344542232622806,
"y2": 0.45016601603464318
}
}
]
}"
Does anyone know how I can get the crop url instead of the original image url?
Upvotes: 2
Views: 2883
Reputation: 1285
You can get the crop URL if you retrieve the image node as IPublishedContent instead of IMedia. This allows you to use the GetCropUrl() method, passing in the alias of the Image Cropper property and the alias of the crop that you need.
var cropUrl = Umbraco.TypedMedia(galleryId).GetCropUrl("modelImage", "modelListCrop");
Upvotes: 6