From 92e93a6cf25880dc9d8ea7e4399d83d49837c1c4 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 17 Jun 2025 13:53:00 -0300 Subject: gen-thumbs: move prepareConvertArgs next to generateImageThumbnails --- src/gen-thumbs.js | 63 +++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 32 deletions(-) (limited to 'src/gen-thumbs.js') diff --git a/src/gen-thumbs.js b/src/gen-thumbs.js index a1c38505..40505189 100644 --- a/src/gen-thumbs.js +++ b/src/gen-thumbs.js @@ -462,37 +462,6 @@ async function getImageMagickVersion(binary) { return match[1]; } -// Write all requested thumbtacks for a source image in one pass -// This saves a lot of disk reads which are probably the main bottleneck -function prepareConvertArgs(filePathInMedia, dirnameInCache, thumbtacks) { - const args = [filePathInMedia, '-strip']; - - const basename = - path.basename(filePathInMedia, path.extname(filePathInMedia)); - - // do larger sizes first - thumbtacks.sort((a, b) => thumbnailSpec[b].size - thumbnailSpec[a].size); - - for (const tack of thumbtacks) { - const {size, quality} = thumbnailSpec[tack]; - const filename = `${basename}.${tack}.jpg`; - const filePathInCache = path.join(dirnameInCache, filename); - args.push( - '(', '+clone', - '-resize', `${size}x${size}>`, - '-interlace', 'Plane', - '-quality', `${quality}%`, - '-write', filePathInCache, - '+delete', ')', - ); - } - - // throw away the (already written) image stream - args.push('null:'); - - return args; -} - async function getSpawnMagick(tool) { if (tool !== 'identify' && tool !== 'convert') { throw new Error(`Expected identify or convert`); @@ -586,6 +555,37 @@ async function determineThumbtacksNeededForFile({ return mismatchedWithinRightSize; } +// Write all requested thumbtacks for a source image in one pass +// This saves a lot of disk reads which are probably the main bottleneck +function prepareConvertArgs(filePathInMedia, dirnameInCache, thumbtacks) { + const args = [filePathInMedia, '-strip']; + + const basename = + path.basename(filePathInMedia, path.extname(filePathInMedia)); + + // do larger sizes first + thumbtacks.sort((a, b) => thumbnailSpec[b].size - thumbnailSpec[a].size); + + for (const tack of thumbtacks) { + const {size, quality} = thumbnailSpec[tack]; + const filename = `${basename}.${tack}.jpg`; + const filePathInCache = path.join(dirnameInCache, filename); + args.push( + '(', '+clone', + '-resize', `${size}x${size}>`, + '-interlace', 'Plane', + '-quality', `${quality}%`, + '-write', filePathInCache, + '+delete', ')', + ); + } + + // throw away the (already written) image stream + args.push('null:'); + + return args; +} + async function generateImageThumbnails(imagePath, thumbtacks, { mediaPath, mediaCachePath, @@ -607,7 +607,6 @@ async function generateImageThumbnails(imagePath, thumbtacks, { await promisifyProcess(spawnConvert(convertArgs), false); } - export async function determineMediaCachePath({ mediaPath, wikiCachePath, -- cgit 1.3.0-6-gf8a5