ethanselzer / react-image-magnify

A responsive image zoom component designed for shopping sites.
https://ethanselzer.github.io/react-image-magnify
MIT License
645 stars 160 forks source link

Dynamic height/width setting #72

Open josieoharrow opened 4 years ago

josieoharrow commented 4 years ago

It would be super helpful to be able to only set width or height and have the other value depend on the native height/width of the image... Is that even possible?

divyanarla commented 4 years ago

the above requested feature would be super useful

divyanarla commented 4 years ago

It would be super helpful to be able to only set width or height and have the other value depend on the native height/width of the image... Is that even possible? you could get the native height/width of the image and set them for the larger image for now, until the issue is addressed. like below function getImgSize(imgSrc) { var newImg = new Image();

newImg.onload = function() {
  var height = newImg.height;
  var width = newImg.width;
  alert ('The image size is '+width+'*'+height);
}

newImg.src = imgSrc; // this must be done AFTER setting onload

}

Rim-777 commented 4 years ago

It would be super helpful to be able to only set width or height and have the other value depend on the native height/width of the image... Is that even possible? you could get the native height/width of the image and set them for the larger image for now, until the issue is addressed. like below function getImgSize(imgSrc) { var newImg = new Image();

newImg.onload = function() {
  var height = newImg.height;
  var width = newImg.width;
  alert ('The image size is '+width+'*'+height);
}

newImg.src = imgSrc; // this must be done AFTER setting onload

}

Just left to understand how to use this function to dynamically set width, height for large images