diff --git a/server/__tests__/converters.spec.js b/server/__tests__/converters.spec.js index 6d6578f..508a03a 100644 --- a/server/__tests__/converters.spec.js +++ b/server/__tests__/converters.spec.js @@ -97,12 +97,12 @@ describe('buildArgs', () => { it('accepts jp2a RGB weight values', () => { expect(buildArgs('jp2a', { red: '0.5', green: '0.3', blue: '0.2' })).toEqual([ - '--red', '0.5', '--green', '0.3', '--blue', '0.2', + '--red=0.5', '--green=0.3', '--blue=0.2', ]) }) it('accepts jp2a edge-threshold', () => { - expect(buildArgs('jp2a', { 'edge-threshold': '0.4' })).toEqual(['--edge-threshold', '0.4']) + expect(buildArgs('jp2a', { 'edge-threshold': '0.4' })).toEqual(['--edge-threshold=0.4']) }) it('accepts valid img2txt format values', () => { diff --git a/server/lib/converters.js b/server/lib/converters.js index f5b5654..eec64b2 100644 --- a/server/lib/converters.js +++ b/server/lib/converters.js @@ -22,6 +22,8 @@ export const SCHEMAS = { format: { type: 'value', valid: ['symbols', 'utf8'] }, }, jp2a: { + _argFormat: 'equals', + size: { type: 'value' }, width: { type: 'value' }, height: { type: 'value' }, chars: { type: 'value' }, @@ -60,6 +62,7 @@ export function buildArgs(tool, flags) { const schema = SCHEMAS[tool] if (!schema) throw new Error(`Unknown tool: ${tool}`) + const equals = schema._argFormat === 'equals' const args = [] for (const [key, value] of Object.entries(flags)) { const def = schema[key] @@ -69,6 +72,8 @@ export function buildArgs(tool, flags) { } if (def.type === 'bool') { if (value) args.push(`--${key}`) + } else if (equals) { + args.push(`--${key}=${String(value)}`) } else { args.push(`--${key}`, String(value)) } @@ -87,7 +92,12 @@ export async function runChafa(imagePath, flags) { } export async function runJp2a(imagePath, flags) { - const args = buildArgs('jp2a', flags) + const { width, height, ...rest } = flags + const processed = { ...rest } + if (width && height) processed.size = `${width}x${height}` + else if (width) processed.size = `${width}x` + else if (height) processed.size = `x${height}` + const args = buildArgs('jp2a', processed) return execa('jp2a', [...args, imagePath], { timeout: TIMEOUT }) }