Skip to content

Commit 97e4c33

Browse files
authored
Merge pull request #72 from shebinleo/replace-gm-lib-with-sharp
replaced gm package with sharp. fixes #71
2 parents 81278f8 + bf4d24b commit 97e4c33

File tree

4 files changed

+830
-100
lines changed

4 files changed

+830
-100
lines changed

lib/ImageProcessor.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
// lib/ImageProcessor.js
2-
const gm = require('gm').subClass({ imageMagick: true });
2+
const sharp = require('sharp');
33

44
/**
55
* Image processing utilities
66
*/
77
class ImageProcessor {
88
static async resize(sourceFilepath, targetFilepath, options) {
9-
return new Promise((resolve, reject) => {
10-
gm(sourceFilepath)
11-
.resize(options.width, options.height, '!')
12-
.write(targetFilepath, (err) => {
13-
if (err) {
14-
reject(new Error(`Image resize failed: ${err.message}`));
15-
return;
16-
}
17-
resolve();
18-
});
19-
});
9+
try {
10+
await sharp(sourceFilepath)
11+
.resize(options.width, options.height, {
12+
fit: 'fill', // equivalent to gm's '!' option for exact dimensions
13+
})
14+
.toFile(targetFilepath);
15+
} catch (err) {
16+
throw new Error(`Image resize failed: ${err.message}`);
17+
}
2018
}
2119
}
2220

0 commit comments

Comments
 (0)