Édouard Lopez
Édouard Lopez

Reputation: 43421

How can I script to export SVG file in both color and monochrome with Inkscape?

I got the following script to export my *.svg to .png in various sizes.

#!/usr/bin/env bash

[[ ! -d png ]] && mkdir png/

for svg in logo.*.svg; do
  echo $svg $png
  sizes=( 64 128 256 512 1024 )
  for size in "${sizes[@]}"; do
    png="png/${svg//.svg/.$size.png}"
    [[ $png =~ vertical ]] && inkscape --without-gui --export-height=$size --export-png="$png" --file="$svg"
    [[ $png =~ horizontal ]] && inkscape --without-gui --export-width=$size --export-png="$png" --file="$svg"
  done
done

As I want to export both monochrome (black & white) and colour version I currently have both SVG version:

  1. logo.bw-horizontal.svg
  2. logo.bw-vertical.svg
  3. logo.horizontal.svg
  4. logo.vertical.svg

Question

How can I improve my script to export in monochrome without the need to have a SVG file in monochrome?

Edit

There is a verb, but not sure how to use it:

org.inkscape.effect.filter.Silhouette: Repaint anything visible monochrome  

Upvotes: 0

Views: 560

Answers (1)

Édouard Lopez
Édouard Lopez

Reputation: 43421

Thanks @Bonanza for the bump

Here are my BATS tests and the related code to do the conversion. It boil down to:

  1. export PNG to PNG
  2. convert PNG to monochrome with convert

    convert "$png" -colorspace Gray "$monochrome"
    

Upvotes: 0

Related Questions