一把umbraco Imagegen GetCropUrl有关API [英] Umbraco Imagegen GetCropUrl on Api

查看:333
本文介绍了一把umbraco Imagegen GetCropUrl有关API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用一把umbraco V7.1 ImageGen。到目前为止这么好,我能够通过我的剃刀代码以获取作物的网址。

I am using ImageGen on Umbraco v7.1. So far so good and am able to get crop urls through my Razor code.

不过,我需要让我的API控制器对作物的网址,但我不确定该怎么做这一点。

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()

...其中 ModelImage 是图像克罗珀数据类型的别名。
这个方法返回src属性的图像URL作物信息一起(加换行符):

...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
      }
    }
  ]
}"

有谁知道我如何能得到作物的网址,而不是原始图像的URL?

Does anyone know how I can get the crop url instead of the original image url?

推荐答案

您可以得到作物URL如果您检索图像节点IPublishedContent而不是互动媒体。这使您可以使用GetCropUrl()方法,传递图像克罗珀财产和你所需要的作物别名的别名。

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

这篇关于一把umbraco Imagegen GetCropUrl有关API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆