Improved animated image handling.
This commit is contained in:
19
src/media.js
19
src/media.js
@@ -319,7 +319,7 @@ async function storeImageFile(media, hashDir, hashSubDir, filename, filedir, fil
|
||||
fsPromises.mkdir(path.join(config.media.path, lazydir), { recursive: true }),
|
||||
]);
|
||||
|
||||
const image = sharp(media.file.path);
|
||||
const image = sharp(media.file.path, { pages: -1 });
|
||||
const isProcessed = media.meta.subtype !== 'jpeg' || media.process;
|
||||
|
||||
const [info, stats] = await Promise.all([
|
||||
@@ -344,10 +344,17 @@ async function storeImageFile(media, hashDir, hashSubDir, filename, filedir, fil
|
||||
}
|
||||
|
||||
if (isProcessed) {
|
||||
// convert to JPEG and write to permanent location
|
||||
await image
|
||||
.jpeg()
|
||||
.toFile(path.join(config.media.path, filepath));
|
||||
if (info.pages) {
|
||||
// convert animated image to WebP and write to permanent location
|
||||
await image
|
||||
.webp()
|
||||
.toFile(path.join(config.media.path, filepath));
|
||||
} else {
|
||||
// convert to JPEG and write to permanent location
|
||||
await image
|
||||
.jpeg()
|
||||
.toFile(path.join(config.media.path, filepath));
|
||||
}
|
||||
}
|
||||
|
||||
// generate thumbnail and lazy
|
||||
@@ -424,7 +431,7 @@ async function storeFile(media, options) {
|
||||
}
|
||||
}
|
||||
|
||||
if (media.meta.type === 'image' && media.meta.subtype !== 'gif') {
|
||||
if (media.meta.type === 'image') {
|
||||
return storeImageFile(media, hashDir, hashSubDir, filename, filedir, filepath, options);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user