This article describes the JavaScript implementation to get picture size and image scaling method. Share to everyone for your reference, specific as follows:
Get picture size:
var originimage = new Image ();
function Getimagewidth (oimage) {
if (originimage.src!= oimage.src) originimage.src = oimage.src;
return originimage.width;
}
function Getimageheight (oimage) {
if (originimage.src!= oimage.src) originimage.src = oimage.src;
return originimage.height;
}
Picture equal scaling:
function SetImage (IMGD, Fitwidth, fitheight) {
var image = new Image ();
IMAGE.SRC = IMGD.SRC;
if (image.width > 0 && image.height > 0) {
if (image.width/image.height >= fitwidth/fitheight) { C5/>if (Image.width > Fitwidth) {
imgd.width = fitwidth;
Imgd.height = (Image.height * fitwidth)/image.width;
} else {
imgd.width = image.width;
Imgd.height = image.height;
}
else {
if (Image.height > Fitheight) {
imgd.height = fitheight;
Imgd.width = (Image.width * fitheight)/image.height;
} else {
imgd.width = image.width;
Imgd.height = Image.height
}}
}
More interested readers of JavaScript-related content can view this site: "JavaScript switching effects and tips summary", "JavaScript graphics Drawing Skills Summary", "JavaScript Search Algorithm Skills summary", " JavaScript animation effects and tips Summary, "JavaScript Error and debugging skills Summary", "JavaScript data structure and algorithm skills summary", "JavaScript traversal algorithm and Skills summary" and "JavaScript Mathematical operation Usage Summary"
I hope this article will help you with your JavaScript programming.