I need to get the original aspect ratio of the image
enter image description here
Expect to get the original aspect ratio of the image
I need to get the original aspect ratio of the image
enter image description here
Expect to get the original aspect ratio of the image
2
Answers
Try this :
const aspectRatio = yourImage.naturalWidth / yourImage.naturalHeight;
console.log(‘Aspect ratio:’, aspectRatio);
Pass the "getAspectRatio()" function an "img.src" parameter.
The actual dimensions of the picture will be taken, after which a check will be made whether the picture is in portrait or landscape format.
As a result, the function returns aspect ratio of the image.