mirror of
https://code.chipmunk.land/Parker2991/NitoriBot/
synced 2026-12-01 14:45:43 -05:00
28 lines
536 B
JavaScript
28 lines
536 B
JavaScript
/**
|
|
* resize image.
|
|
* @param {number} width width
|
|
* @param {number} height height
|
|
* @return {object} width and height
|
|
*/
|
|
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 }
|