Resize Image Width Or Height

function ResizeImage(ImgD) { var myImage = new Image(); var iwidth = 145; //define permissible max-width var iheight = 108; //define permissible max-height myImage.src = ImgD.src; if (myImage.width > 0 && myImage.height > 0) { if (myImage.width / myImage.height >= iwidth / iheight) { if (myImage.width > iwidth) { ImgD.width = iwidth; ImgD.height = (myImage.height * iwidth) / myImage.width; } else { ImgD.width = myImage.width; ImgD.height = myImage.height; } }else { if (myImage.height > iheight) { ImgD.height = iheight; ImgD.width = (myImage.width * iheight) / myImage.height; }else { ImgD.width = myImage.width; ImgD.height = myImage.height; } } } } //how to use //<img onload="ResizeImage(this)" src="placehold.png">

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.