mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 19:14:16 +00:00
use aspect ratio to rescale
This commit is contained in:
parent
bb3b8a150f
commit
195c585049
@ -11,6 +11,7 @@
|
|||||||
"@aws-sdk/client-s3": "^3.310.0",
|
"@aws-sdk/client-s3": "^3.310.0",
|
||||||
"@corenode/utils": "0.28.26",
|
"@corenode/utils": "0.28.26",
|
||||||
"@foxify/events": "^2.1.0",
|
"@foxify/events": "^2.1.0",
|
||||||
|
"@jimp/plugin-scale": "^0.22.7",
|
||||||
"@tensorflow/tfjs-node": "4.0.0",
|
"@tensorflow/tfjs-node": "4.0.0",
|
||||||
"aws-sdk": "^2.1355.0",
|
"aws-sdk": "^2.1355.0",
|
||||||
"axios": "^1.2.5",
|
"axios": "^1.2.5",
|
||||||
|
@ -44,10 +44,24 @@ async function processImage(file) {
|
|||||||
|
|
||||||
if (width > maximuns.imageResolution.width || height > maximuns.imageResolution.height) {
|
if (width > maximuns.imageResolution.width || height > maximuns.imageResolution.height) {
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
|
// calculate max resolution respecting aspect ratio
|
||||||
|
const resizedResolution = {
|
||||||
|
width: maximuns.imageResolution.width,
|
||||||
|
height: maximuns.imageResolution.height,
|
||||||
|
}
|
||||||
|
|
||||||
|
if (width > height) {
|
||||||
|
resizedResolution.height = Math.floor((height / width) * maximuns.imageResolution.width)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (height > width) {
|
||||||
|
resizedResolution.width = Math.floor((width / height) * maximuns.imageResolution.height)
|
||||||
|
}
|
||||||
|
|
||||||
Jimp.read(file.filepath)
|
Jimp.read(file.filepath)
|
||||||
.then((image) => {
|
.then((image) => {
|
||||||
image
|
image
|
||||||
.resize(maximuns.imageResolution.width, maximuns.imageResolution.height)
|
.resize(resizedResolution.width, resizedResolution.height)
|
||||||
.quality(maximuns.imageQuality)
|
.quality(maximuns.imageQuality)
|
||||||
.write(file.filepath, resolve)
|
.write(file.filepath, resolve)
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user