Im trying to match some vectors above a Image
comonent. In order to do this pixel-perfect, I need to know the size of the image displayed inside Image
component.
At this point I have the width and height of the component layout, but can't figure out how to calculate the width and height of the image once is inside the Image
component.
I tried to calculate the following way with the proportions of with and viceversa, but there are some cases (specially vertical image) where this does not work.
/*
Calculate proportional width of displayed image:
photo.width -> width
photo.height -> x
*/
var x = (width * photo.height) / photo.width;
/*
calculate proportional height of displayed image:
photo.height -> height
photo.width -> y
*/
var y = (height * photo.width) / photo.height;