feat: add cover-image task to export cover PDF as 300 DPI PNG
Runs Ghostscript on output/cover.pdf to produce output/cover-300dpi.png for visual QC and sharing. Also wired into the `pnpm all` pipeline. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { access, stat } from 'fs/promises';
|
||||
import { resolve, dirname } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { execFile } from 'child_process';
|
||||
import { promisify } from 'util';
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
const __dir = dirname(fileURLToPath(import.meta.url));
|
||||
const root = resolve(__dir, '..');
|
||||
const pdfPath = resolve(root, 'output', 'cover.pdf');
|
||||
const outPath = resolve(root, 'output', 'cover-300dpi.png');
|
||||
|
||||
try {
|
||||
await access(pdfPath);
|
||||
} catch {
|
||||
console.error('output/cover.pdf not found — run `pnpm cover` first');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log('Rendering cover to PNG at 300 DPI…');
|
||||
|
||||
await execFileAsync('gs', [
|
||||
'-dBATCH', '-dNOPAUSE', '-dQUIET',
|
||||
'-sDEVICE=png16m',
|
||||
'-r300',
|
||||
`-sOutputFile=${outPath}`,
|
||||
pdfPath,
|
||||
]);
|
||||
|
||||
const { size } = await stat(outPath);
|
||||
console.log(`Cover image: output/cover-300dpi.png (${(size / 1_048_576).toFixed(1)} MB)`);
|
||||
Reference in New Issue
Block a user