|
|
@@ -15,18 +15,21 @@ class SharpWrapper {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- async convert(fileObj, width, height, quality) {
|
|
|
+ async convert(fileObj, width, height, quality, keepMeta) {
|
|
|
const output = tmp.fileSync({ discardDescriptor: true });
|
|
|
|
|
|
let result = null;
|
|
|
try {
|
|
|
- result = await this.#threadPool.pushTask(() =>
|
|
|
- new Sharp(fileObj.path)
|
|
|
- .resize(width, height, { fit: "inside", withoutEnlargement: true })
|
|
|
+ result = await this.#threadPool.pushTask(async () => {
|
|
|
+ let sharpInst = new Sharp(fileObj.path);
|
|
|
+ if (keepMeta)
|
|
|
+ sharpInst = await sharpInst.keepMetadata();
|
|
|
+ return sharpInst
|
|
|
.rotate()
|
|
|
+ .resize(width, height, { fit: "inside", withoutEnlargement: true })
|
|
|
.jpeg({ quality: quality *10 })
|
|
|
.toFile(output.name)
|
|
|
- );
|
|
|
+ });
|
|
|
} catch (err) {
|
|
|
console.error("Sharp::createThumbnail: ", err);
|
|
|
output.removeCallback();
|
|
|
@@ -84,7 +87,7 @@ module.exports.parse = async (fileObj) => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-module.exports.createThumbnail = (fileObj, width, height, quality) => {
|
|
|
- return sh.convert(fileObj, width, height, quality);
|
|
|
+module.exports.createThumbnail = (fileObj, width, height, quality, keepMeta) => {
|
|
|
+ return sh.convert(fileObj, width, height, quality, keepMeta);
|
|
|
};
|
|
|
|