Improved animated image handling.

This commit is contained in:
DebaucheryLibrarian
2021-02-11 01:46:11 +01:00
parent 42a2fd8800
commit a14227b588
106 changed files with 21 additions and 7 deletions

View File

@@ -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);
}

View File

@@ -1,5 +1,7 @@
'use strict';
const mime = require('mime');
const qu = require('../utils/qu');
const http = require('../utils/http');
const slugify = require('../utils/slugify');
@@ -31,7 +33,11 @@ function scrapeSceneX(scene) {
release.stars = scene.rating;
release.tags = scene.tags.map(tag => tag.name);
release.poster = scene.thumb;
if (mime.getType(scene.thumb) === 'image/gif') {
release.teaser = scene.thumb;
} else {
release.poster = scene.thumb;
}
release.channel = slugify(scene.sites[0]?.name, '');