Skip to content

Instantly share code, notes, and snippets.

@mtmzorro
Last active August 29, 2015 14:02
Show Gist options
  • Save mtmzorro/d7a242ec645c6934dc44 to your computer and use it in GitHub Desktop.
Save mtmzorro/d7a242ec645c6934dc44 to your computer and use it in GitHub Desktop.
function resizeImage(oldImg, height){
var image = new Image();
image.src = oldImg.src;
var d = image.width / image.height;
var newWidth = height * d;
var newHeight = height;
oldImg.style.width = newWidth + 'px';
oldImg.style.height = newHeight + 'px';
}
var imgTest = document.getElementById('testImg');
var divTest = document.getElementById('testDiv');
console.log(parseInt(divTest.style.height, 10))
imgTest.onload = function(){
resizeImage(this, 600);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment