Umbraco Imagegen GetCropUrl on Api

流过昼夜 提交于 2019-12-10 10:45:54

问题


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?


回答1:


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");


来源:https://stackoverflow.com/questions/29560136/umbraco-imagegen-getcropurl-on-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!