Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add custom batch-sizing to cli options #200

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Otherwise, you can install manually by downloading the latest release then addin
--number-of-colors <n> ImageAlpha palette size, defaults to 256
--quality <min>-<max> ImageAlpha quality range from 0-100, defaults to 65-80
--speed <n> ImageAlpha speed from 1 (brute-force) to 10 (fastest), defaults to 1
--batch-size <n> set batch size for processing images, defaults to 300
-h, --help output usage information

Supported Apps:
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
7 changes: 6 additions & 1 deletion src/imageoptim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -37,6 +38,10 @@ program
.option(
'--speed <n>',
`ImageAlpha speed from 1 (brute-force) to 10 (fastest), defaults to ${PNGQUANT_SPEED}`,
)
.option(
'--batch-size <n>',
`batch size (lower this number for older machines), defaults to ${BATCH_SIZE}`,
);

program.on('--help', () => {
Expand Down Expand Up @@ -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,
Expand Down