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