Crate svg_invert

source ·
Expand description

§Invert SVG

invert_svg is a CLI utility and a library that inverts the colors of an SVG file.

§Usage as a CLI utility

invert-svg < input.svg > output.svg

§Usage as a library

use std::io::{stdin, stdout, BufReader, BufWriter, Write};
use svg_invert::invert_svg;

let reader = BufReader::new(stdin());
let writer = BufWriter::new(stdout());
match invert_svg(reader, writer) {
  Ok(_) => {
    // makes sure to flush stdout before exiting
    // since we are using a BufWriter
    match stdout().flush() {
      Ok(_) => {}
      Err(e) => {
        eprintln!("Error: {e}");
      }
    }
  }
  Err(e) => {
    eprintln!("Error: {e}");
  }
}

§Processing multiple images

svg_invert::invert_svg is a shortcut for creating a new InvertSvg instance and calling its invert_svg method.

If you intend to process multiple SVG images in the same program, it might be beneficial to create a single InvertSvg instance and reuse it.

In fact, an InvertSvg instance holds an internal cache that stores the inverted colors of the SVG images it processes. So, by reusing the same instance, you might have some performance gains if your images happen to share the same colors.

use svg_invert::InvertSvg;

let invert_svg = InvertSvg::new();
// call invert_svg.invert_svg multiple times

Structs§

  • Struct that inverts the colors of an SVG file. It holds an internal cache that stores the inverted colors of the SVG images it processes. By reusing the same instance, you might have some performance gains if your images happen to share the same colors.

Enums§

  • Error type for InvertSvg. It can be an IO error, an XML read error, or an XML write error.

Functions§

  • Inverts the colors of an SVG file. The input is a reader that reads the SVG content, and the output is a writer that is used to write the inverted SVG content. This is a shortcut for creating a new InvertSvg instance and calling its invert_svg method.