首页 > 代码库 > Umbraco image中使用Crop URL

Umbraco image中使用Crop URL

需要在Umbraco 的image中使用crop URL.首先你需要取出这个image作为IPublishedContent

有以下两种方法

第一种:

var imageId = Model.Content.GetPropertyValue<int>("image");
var image = Umbraco.TypedMedia(imageId);

第二种,如果你已经使用了Core Property Value Converters package, 你可以直接取出

var image = Model.Content.GetPropertyValue<IPublishedContent>("image");

You then need to call the GetCropUrl() method on your image. If you‘ve replaced the default Upload property with an Image Cropper property, and kept the property alias the same (umbracoFile), you can just pass in the crop alias:

var cropUrl = image.GetCropUrl("my-crop-name");

If the alias of your Image Cropper property is different to the default you will need to pass that as an additional argument:

var cropUrl = image.GetCropUrl("imageCropperAlias", "my-crop-name");

Umbraco image中使用Crop URL