chomens-bot-js/util/image.js

28 lines
542 B
JavaScript
Raw Normal View History

2022-11-15 21:33:16 -05:00
/**
* resize image.
* @param {number} width width
* @param {number} height height
* @return {object} width and height
*/
2022-10-15 08:53:48 -04:00
function resize(width, height) {
const aspectRatio = width / height;
let optimalWidth = Math.round(aspectRatio * 20 * (27 / 3));
let optimalHeight = 20;
if (optimalWidth > 320) {
const reduction = optimalWidth / 320;
optimalWidth = 320;
optimalHeight *= reduction;
}
return {
width: Math.floor(optimalWidth),
height: Math.floor(optimalHeight),
};
}
module.exports = {resize};