Added media resize.

This commit is contained in:
DebaucheryLibrarian 2022-02-12 17:16:20 +01:00
parent c7c62e220d
commit 5da1acc38d
2 changed files with 15 additions and 7 deletions

View File

@ -320,6 +320,8 @@ module.exports = {
}, },
media: { media: {
path: './media', path: './media',
maxSize: 1000,
quality: 80,
thumbnailSize: 320, // width for 16:9 will be exactly 576px thumbnailSize: 320, // width for 16:9 will be exactly 576px
thumbnailQuality: 100, thumbnailQuality: 100,
lazySize: 90, lazySize: 90,

View File

@ -345,12 +345,13 @@ async function writeImage(image, media, info, filepath, isProcessed) {
return; return;
} }
if (isProcessed) { await image
// convert to JPEG and write to permanent location .resize({
await image height: config.media.maxSize,
.jpeg() withoutEnlargement: true,
.toFile(path.join(config.media.path, filepath)); })
} .jpeg({ quality: config.media.quality })
.toFile(path.join(config.media.path, filepath));
} }
async function writeThumbnail(image, thumbpath) { async function writeThumbnail(image, thumbpath) {
@ -416,12 +417,14 @@ async function storeImageFile(media, hashDir, hashSubDir, filename, filedir, fil
}); });
} }
await writeImage(image, media, info, filepath, isProcessed);
await Promise.all([ await Promise.all([
writeImage(image, media, info, filepath, isProcessed),
writeThumbnail(image, thumbpath), writeThumbnail(image, thumbpath),
writeLazy(image, lazypath), writeLazy(image, lazypath),
]); ]);
/*
if (isProcessed) { if (isProcessed) {
// file already stored, remove temporary file // file already stored, remove temporary file
await fsPromises.unlink(media.file.path); await fsPromises.unlink(media.file.path);
@ -429,6 +432,9 @@ async function storeImageFile(media, hashDir, hashSubDir, filename, filedir, fil
// image not processed, simply move temporary file to final location // image not processed, simply move temporary file to final location
await fsPromises.rename(media.file.path, path.join(config.media.path, filepath)); await fsPromises.rename(media.file.path, path.join(config.media.path, filepath));
} }
*/
await fsPromises.unlink(media.file.path);
if (config.s3.enabled) { if (config.s3.enabled) {
await Promise.all([ await Promise.all([