« get me outta code hell

gen-thumbs: move prepareConvertArgs next to generateImageThumbnails - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/gen-thumbs.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2025-06-17 13:53:00 -0300
committer(quasar) nebula <qznebula@protonmail.com>2025-06-17 13:53:00 -0300
commit92e93a6cf25880dc9d8ea7e4399d83d49837c1c4 (patch)
treef11cd86bb804bee494cb7cf87e20beacf25dcecd /src/gen-thumbs.js
parent1e328fef102d763f7283149978601115d701d906 (diff)
gen-thumbs: move prepareConvertArgs next to generateImageThumbnails preview
Diffstat (limited to 'src/gen-thumbs.js')
-rw-r--r--src/gen-thumbs.js63
1 files changed, 31 insertions, 32 deletions
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,