Posted on 31/01/2019 12:59:33
Hi Hans
Requirements
- First enable focal point selector for paragraphs or item fields. See dump 1 and dump 2.
- Then implement in the template (see below and attached templates in zip for examples)
- Focal points will only work if you have both a width and a height and a cropping mode that requires cropping, i.e. crop=0-4 and 7 (new). Crop=5 will not use focal points as that mode will ensure that the entire image is inside the desired image box.
Find a test page here: https://doc.dynamicweb.com/admin/examples/GetImageFocalTest.html
The focal points are relative in percent to the center of the image. The center is focal 0,0. Then you can move it left/right on the x-axis compared to center. x=-100 is left edge, x=100 is right edge. Y-axis is up (y=100) and down (y=-100). So a focal point is i.e. x=-40,y=-20, meaning in the lower left square of the image.
Template tag examples
Example 1, using template tags:
@inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>>
@{
var image = GetString("ParagraphImageClean");
var parameters = GetString("ParagraphImage.FocalPointParameters");
var imageFocalX = GetString("ParagraphImage.FocalX");
var imageFocalY = GetString("ParagraphImage.FocalY");
var imageHasFocalPoint = GetBoolean("ParagraphImage.ImageHasFocalPoint");
}
<img src="/Admin/Public/GetImage.ashx?Image=@image&Format=jpg&Width=50&height=200&crop=7&@parameters" />
Example 2, using viewmodel templates:
@inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel>
@{
var image = Model.Image;
var parameters = Model.GetImageFocalPointParameters();
var imageFocalX = Model.ImageFocalX;
var imageFocalY = Model.ImageFocalY;
var imageHasFocalPoint = Model.ImageHasFocalPoint();
}
<img src="/Admin/Public/GetImage.ashx?Image=@image&Format=jpg&Width=50&height=200&crop=7&@parameters" />
BR Nicolai