Skip to contents

Build a dark-mode variant of an SVG image by replacing every colour with its RGB complement. Both the hexadecimal notation used by svglite and the rgb() notation written by cairo-based devices such as grDevices::svg() are understood. Elements that do not set their own fill would keep the SVG default black, so default_fill is written on the root <svg> element, where those elements inherit it.

Usage

invert_svg(
  path,
  output = NULL,
  default_fill = "#ffffff",
  invert_raster = TRUE,
  quiet = FALSE
)

Arguments

path

Path to the input SVG file.

output

Path of the output SVG. Defaults to the input name with a -dark suffix next to it. Use NA to return the modified SVG as a string without writing a file.

default_fill

Fill written on the root <svg> element, so elements without their own fill do not stay black. Use NULL to leave the root element untouched.

invert_raster

Whether to complement the colours of embedded raster images as well. Default is TRUE. Requires the png package.

quiet

Whether to suppress the message about the written file. Default is FALSE.

Value

The output path, invisibly, or the modified SVG as a string when output is NA.