Is it posible to getGet width and height of image after setting maxHeight and maxWidth with javascript.
$new_image = new Image();
$new_image.src = 'xxx.jpg';
$new_image.style.maxHeight = '500px';
$new_image.style.maxWidth = '600px';
$new_image.style.height = 'auto';
$new_image.style.width = 'auto';
alert('CURRENT WIDTH AND HEIGHT IF IMAGE IS 1000 X 1000 PX');
I know how to get the maxheight value, but that might not be the actual size since the image is set to height and width “auto”.
No jquery answers thank you! 🙂
offsetHeightandoffsetWidthwill get you what you want, and take into account the maxWidth and maxHeight. Do keep in mind that the img object needs to be part of the DOM to have any dimensions at all. So you’ll need to add it with something likedocument.body.appendChild($new_image)before offsetHeight and width will return anything useful.