chore(icons): simplify to ImageMagick-only rasterization path
This commit is contained in:
parent
39a0a34a65
commit
81ced7369d
2 changed files with 16 additions and 36 deletions
|
|
@ -24,4 +24,4 @@ Notes
|
|||
- `ICON_COLOR_TOOLBAR` (16/32); default `#5AC3D6`.
|
||||
- Firefox does not require .ico; PNG is recommended.
|
||||
- Theme variants can be added later via `browser_action.theme_icons`.
|
||||
- Rasterizer: the script will use `rsvg-convert` if available, then `inkscape`, and falls back to ImageMagick (`magick`/`convert`). Install one of these locally.
|
||||
- Rasterizer: uses ImageMagick only (`magick` or `convert`). Ensure your ImageMagick build supports reading SVG (via `librsvg` or compatible delegate).
|
||||
|
|
|
|||
|
|
@ -28,22 +28,13 @@ const TOOLBAR_SIZES = [16, 32];
|
|||
const COLOR_ADDON = process.env.ICON_COLOR_ADDON || '#223544';
|
||||
const COLOR_TOOLBAR = process.env.ICON_COLOR_TOOLBAR || '#5AC3D6';
|
||||
|
||||
function which(cmd, args = ['--version']) {
|
||||
function ensureMagick() {
|
||||
try {
|
||||
const res = spawnSync(cmd, args, { stdio: 'ignore' });
|
||||
return res && res.status === 0;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function ensureRasterizer() {
|
||||
// Prefer rsvg-convert (librsvg), then Inkscape, then ImageMagick.
|
||||
if (which('rsvg-convert', ['-v'])) return { kind: 'rsvg', bin: 'rsvg-convert' };
|
||||
// Inkscape 1.x CLI: --pipe reads from stdin
|
||||
if (which('inkscape', ['--version'])) return { kind: 'inkscape', bin: 'inkscape' };
|
||||
if (which('magick', ['-version'])) return { kind: 'magick', bin: 'magick' };
|
||||
if (which('convert', ['-version'])) return { kind: 'magick', bin: 'convert' };
|
||||
let res = spawnSync('magick', ['-version'], { stdio: 'ignore' });
|
||||
if (res && res.status === 0) return 'magick';
|
||||
res = spawnSync('convert', ['-version'], { stdio: 'ignore' });
|
||||
if (res && res.status === 0) return 'convert';
|
||||
} catch (_) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -71,30 +62,19 @@ function colorize(svg, color) {
|
|||
return s;
|
||||
}
|
||||
|
||||
function rasterize(raster, svgString, size, outPath) {
|
||||
let args;
|
||||
let cmd = raster.bin;
|
||||
if (raster.kind === 'rsvg') {
|
||||
// rsvg-convert reads SVG and outputs PNG; specify size and transparent background
|
||||
args = ['-f', 'png', '-w', String(size), '-h', String(size), '--background-color=transparent', '-o', outPath, '-'];
|
||||
} else if (raster.kind === 'inkscape') {
|
||||
// Inkscape 1.x: --export-type=png --export-filename=out --export-width/height, read from stdin via --pipe
|
||||
args = ['--export-type=png', `--export-filename=${outPath}`, `--export-width=${size}`, `--export-height=${size}`, '--pipe'];
|
||||
} else {
|
||||
// ImageMagick
|
||||
args = ['-background', 'none', '-density', '384', 'svg:-', '-resize', `${size}x${size}`, outPath];
|
||||
}
|
||||
const proc = spawnSync(cmd, args, { input: svgString, stdio: ['pipe', 'inherit', 'inherit'] });
|
||||
function rasterize(magickBin, svgString, size, outPath) {
|
||||
const args = ['-background', 'none', '-density', '384', 'svg:-', '-resize', `${size}x${size}`, outPath];
|
||||
const proc = spawnSync(magickBin, args, { input: svgString, stdio: ['pipe', 'inherit', 'inherit'] });
|
||||
if (proc.status !== 0) {
|
||||
console.error(`Failed to generate ${outPath} using ${raster.kind} (${cmd}).`);
|
||||
console.error(`Failed to generate ${outPath} using ${magickBin}.`);
|
||||
process.exit(proc.status || 1);
|
||||
}
|
||||
}
|
||||
|
||||
function main() {
|
||||
const raster = ensureRasterizer();
|
||||
if (!raster) {
|
||||
console.error('No SVG rasterizer found. Install one of: rsvg-convert, inkscape, or ImageMagick (magick/convert).');
|
||||
const magick = ensureMagick();
|
||||
if (!magick) {
|
||||
console.error('ImageMagick not found. Please install ImageMagick (magick or convert) and ensure SVG support is available.');
|
||||
process.exit(1);
|
||||
}
|
||||
if (!fs.existsSync(ICONS_DIR)) fs.mkdirSync(ICONS_DIR, { recursive: true });
|
||||
|
|
@ -105,7 +85,7 @@ function main() {
|
|||
const addonSvg = colorize(base, COLOR_ADDON);
|
||||
for (const s of ADDON_SIZES) {
|
||||
const out = path.join(ICONS_DIR, `icon-${s}.png`);
|
||||
rasterize(raster, addonSvg, s, out);
|
||||
rasterize(magick, addonSvg, s, out);
|
||||
console.log(`Generated ${path.relative(REPO_ROOT, out)}`);
|
||||
}
|
||||
|
||||
|
|
@ -113,7 +93,7 @@ function main() {
|
|||
const toolbarSvg = colorize(base, COLOR_TOOLBAR);
|
||||
for (const s of TOOLBAR_SIZES) {
|
||||
const out = path.join(ICONS_DIR, `icon-${s}.png`);
|
||||
rasterize(raster, toolbarSvg, s, out);
|
||||
rasterize(magick, toolbarSvg, s, out);
|
||||
console.log(`Generated ${path.relative(REPO_ROOT, out)}`);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue