Problem definition
I have to render a image as if it were cropped inside a container. The only data I have is the img URL and its bounds in percentages values, expressed as numeric values (left: 86, top: 72, right: 99, bottom: 12, etc...). As you could imagine, the image is bigger than its container.
Code Snippet
Javascript
get pictureProperties() {
const pic = this.discovery.img;
const x = this.discovery.crop_percentages.left + '%';
const y = (100 - this.discovery.crop_percentages.top) + '%';
return `background-image: url(${pic}); background-position: ${x} ${y}`;
}
Pug
.photo-wrapper(style="{{::$ctrl.pictureProperties}}"
Issues
I tried to position the image as a background inside the container without any luck, because percentage values work as follows with background-images:
While I need something like the absolute values positioning but using this percentages values.
Any idea of how can I work around this issue?