From bab1f7fa706c8d1b27dcf6264c2ae42bf98b8a5e Mon Sep 17 00:00:00 2001 From: Troy McCall Date: Sun, 26 Nov 2023 13:28:00 -0500 Subject: [PATCH] feat: add custom batch-sizing to cli options --- README.md | 1 + src/constants.ts | 1 + src/imageoptim.ts | 7 ++++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b407bc0..91be73d 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,7 @@ Otherwise, you can install manually by downloading the latest release then addin --number-of-colors ImageAlpha palette size, defaults to 256 --quality - ImageAlpha quality range from 0-100, defaults to 65-80 --speed ImageAlpha speed from 1 (brute-force) to 10 (fastest), defaults to 1 + --batch-size set batch size for processing images, defaults to 300 -h, --help output usage information Supported Apps: diff --git a/src/constants.ts b/src/constants.ts index 6badf4b..acdefa2 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -45,6 +45,7 @@ export const VERSION = manifest.version; export const PNGQUANT_NUMBER_OF_COLORS = '256'; export const PNGQUANT_QUALITY = '65-80'; export const PNGQUANT_SPEED = '1'; +export const BATCH_SIZE = '300'; export const PNGQUANT_BIN_PATH = '/Applications/ImageAlpha.app/Contents/MacOS/pngquant'; export const IMAGEOPTIM_BIN_PATH = '/Applications/ImageOptim.app/Contents/MacOS/ImageOptim'; diff --git a/src/imageoptim.ts b/src/imageoptim.ts index 56d1b24..262a8b6 100644 --- a/src/imageoptim.ts +++ b/src/imageoptim.ts @@ -4,6 +4,7 @@ import { sync } from 'globby'; import { homedir } from 'os'; import { cli } from './'; import { + BATCH_SIZE, PNGQUANT_NUMBER_OF_COLORS, PNGQUANT_QUALITY, PNGQUANT_SPEED, @@ -37,6 +38,10 @@ program .option( '--speed ', `ImageAlpha speed from 1 (brute-force) to 10 (fastest), defaults to ${PNGQUANT_SPEED}`, + ) + .option( + '--batch-size ', + `batch size (lower this number for older machines), defaults to ${BATCH_SIZE}`, ); program.on('--help', () => { @@ -88,7 +93,7 @@ const filePaths = sync(patterns.map((pattern) => pattern.replace('~', homedir()) const options = program.opts(); cli({ - batchSize: 300, + batchSize: options.batchSize || BATCH_SIZE, enabled: { color: options.color === true, imageAlpha: options.imagealpha === true,