jacksorjacksor (Richard Jackson)
10/11/2023, 9:36 AMbackground-image
style of a div
ignores this focal point.
Snippet 1: full viewport height image, ignores focal point
<div class="bg-image" style="background-image: url('@imgUrl'); height: 100vh"></div>
I spent a short while looking in the database to find where the focal co-ordinates would be stored, more for my own interest, but couldn't find them.
TIA!
RichD_Inventor
10/11/2023, 11:08 AMjacksorjacksor (Richard Jackson)
10/11/2023, 11:24 AMskttl
10/11/2023, 11:28 AMMediaWithCrops
) has a LocalCrops property, which is an ImageCropperValue
(the umbracoFile property on the media item is the same). In this ImageCropperValue, there is a property called FocalPoint, which contains properties for Top and Left. Note, these are decimals, so to get them working with a background position, you need to multiply by 100.
eg. style="background-position: @(media.LocalCrops.FocalPoint?.Top ?? 0.5 * 100)% @(media.LocalCrops.FocalPoint?.Left ?? 0.5 * 100)%"
jacksorjacksor (Richard Jackson)
10/11/2023, 11:36 AMjacksorjacksor (Richard Jackson)
10/11/2023, 11:36 AMjacksorjacksor (Richard Jackson)
10/11/2023, 5:02 PMFocalPoint.Top/Left
return decimals, so I had to cast the double 0.5
as `(decimal) 0.5`:
html
<div class="bg-image"
style="background-image: url('@imgUrl');
height: 100vh;
background-position: @(Model.MainImage.LocalCrops.FocalPoint?.Top ?? 0.5m * 100)% @(Model.MainImage.LocalCrops.FocalPoint?.Left ?? 0.5m * 100)%">
</div>
D_Inventor
10/11/2023, 6:54 PMD_Inventor
10/11/2023, 6:55 PMjacksorjacksor (Richard Jackson)
10/12/2023, 9:07 AMjacksorjacksor (Richard Jackson)
10/12/2023, 9:07 AM