Developer forum

Forum » CMS - Standard features » Image Focal Point - how to set it up in the template

Image Focal Point - how to set it up in the template

Hans Ravnsfjall
Hans Ravnsfjall
Reply

Hi

I´ve been looking at the release notes, and searching the forum - for how to use the image focal point in the template, but no luck

Anybody who can how i activate it in the template? Is it a parameter for the getimage.ashx like eg. Crop=FocalPoint ?

/Hans

 


Replies

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply
This post has been marked as an answer

HI Hans,

 

It is in the release notes, but further down. Check here https://www.screencast.com/t/giRXdwQtU

 

Best Regards,

Nuno Aguiar

Votes for this answer: 1
 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

aha!

 

Thank you Nuno :)

 

/Hans

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

But it does not say how to use it in the template?

Does anybody have an example on how to use it in a template?

/Hans

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

I have been trying this

http://sstemplate.dw9demo.dynamicweb-cms.com/Admin/Public/Getimage.ashx?image=/Files/Images/Tidindi/Hiking%20Boots%20(2018).jpg&width=900&height=100&ImageFocalX=-86&ImageFocalY=90&HasFocalPoint=true

but it doesn´t work.

Anyone have an example on how to use it in a template?

/Hans

 
Steffen Kruse Hansen Dynamicweb Employee
Steffen Kruse Hansen
Reply
This post has been marked as an answer

Hi Hans,

It should be something like this:

/Admin/Public/Getimage.ashx?image=/Files/Images/Tidindi/Hiking%20Boots%20(2018).jpg&width=900&height=100&Crop=7&x=-86&y=90

x, y is the coordinate of the Image focal point, where x=100, y=100 is the center of the image.

Best regards,

Steffen

Votes for this answer: 1
 
Steffen Kruse Hansen Dynamicweb Employee
Steffen Kruse Hansen
Reply
This post has been marked as an answer

Correction:

x=100, y=100 is not the center of the image. x=0, y=0 should be the center of the image, and x=100, y=100 should be the upper right corner

Votes for this answer: 1
 
Nicolai Pedersen
Reply
This post has been marked as an answer

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

Capture.PNG Capture2.PNG Capture3.PNG Focals2.PNG
Votes for this answer: 1
 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Yes, perfect :)

Thanx for the help guys :) Got it to work, and altough it might seem a small matter - this might just be the best thing since sliced bread :)

 

/Hans

 
Jacob Storgaard Jensen
Reply

Hi Nicolai, how to get the Focal Point data into an index for use on a QueryPublisher list?

 
Nicolai Pedersen
Reply

Hi Jacob

They will be indexed as part of the filepath in the format filename.jpg?x=123&y=345 - you can then just replace the ? with & and add the path to getimage.ashx.

BR Nicolai

 
Jacob Storgaard Jensen
Reply
Original message by Nicolai Pedersen posted on 07/02/2019 13:14:32:

Hi Jacob

They will be indexed as part of the filepath in the format filename.jpg?x=123&y=345 - you can then just replace the ? with & and add the path to getimage.ashx.

BR Nicolai

What determines wheter or not the parameters are automatically a part of the filepath or not? Right now I did a Itempublisher list, and here it isn't a part of the filepath... would be nice with just one apporach... but then again I do see that you might have had some performance considerations on indexes etc...

 
Nicolai Pedersen
Reply

The parameters are only part of a tag if they come directly from database or index. If they come out of a module, paragraph or item, the parameters are found in seperate tags.

BR Nicolai

 
Jacob Storgaard Jensen
Reply

Shouldn't you be sleeping now? :-D
But good to see I'm not the only one working late :-S

 

You must be logged in to post in the forum