You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.4 KiB
57 lines
1.4 KiB
2 years ago
|
function getImgSize(width, height) {
|
||
|
var maxWidth = 180, maxHeight = 180;
|
||
|
if (width === height) {
|
||
|
return {
|
||
|
width: width > maxWidth ? maxWidth : width,
|
||
|
height: height > maxHeight ? maxHeight : height
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (width > height) {
|
||
|
if (width > maxWidth && height > maxHeight) {
|
||
|
return {
|
||
|
width: maxWidth,
|
||
|
height: Number(((maxWidth / width) * height).toFixed(2))
|
||
|
}
|
||
|
} else if (width > maxWidth && height < maxHeight) {
|
||
|
return {
|
||
|
width: maxWidth,
|
||
|
height: Number(((maxWidth / width) * height).toFixed(2))
|
||
|
}
|
||
|
} else if (width < maxWidth && height > maxHeight) {
|
||
|
return {
|
||
|
width: Number(((maxHeight / height) * width).toFixed(2)),
|
||
|
height: maxHeight
|
||
|
}
|
||
|
} else {
|
||
|
return {
|
||
|
width: width,
|
||
|
height: height
|
||
|
}
|
||
|
}
|
||
|
|
||
|
} else {
|
||
|
if (width > maxWidth && height > maxHeight) {
|
||
|
return {
|
||
|
width: Number(((maxHeight / height) * width).toFixed(2)),
|
||
|
height: maxHeight
|
||
|
}
|
||
|
} else if (width > maxWidth && height < maxHeight) {
|
||
|
return {
|
||
|
width: width,
|
||
|
height: maxHeight
|
||
|
}
|
||
|
} else if (width < maxWidth && height > maxHeight) {
|
||
|
return {
|
||
|
width: Number(((maxHeight / height) * width).toFixed(2)),
|
||
|
height: maxHeight
|
||
|
}
|
||
|
} else {
|
||
|
return {
|
||
|
width: width,
|
||
|
height: height
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|