Note: This document is incomplete and work-in-progress.
Here are different ways to convert (or rasterize) SVG graphics to PNG.
brew install librsvg
Then the rsvg-convert
command should be available in your terminal.
rsvg-convert --help
# Usage:
# rsvg-convert [OPTION…] [FILE...] - SVG Converter
#
# Help Options:
# -?, --help Show help options
#
# Application Options:
# -d, --dpi-x=<float> pixels per inch [optional; defaults to 90dpi]
# -p, --dpi-y=<float> pixels per inch [optional; defaults to 90dpi]
# -x, --x-zoom=<float> x zoom factor [optional; defaults to 1.0]
# -y, --y-zoom=<float> y zoom factor [optional; defaults to 1.0]
# -z, --zoom=<float> zoom factor [optional; defaults to 1.0]
# -w, --width=<int> width [optional; defaults to the SVG's width]
# -h, --height=<int> height [optional; defaults to the SVG's height]
# -f, --format=[png, pdf, ps, eps, svg, xml, recording] save format [optional; defaults to 'png']
# -o, --output output filename [optional; defaults to stdout]
# -i, --export-id=<object id> SVG id of object to export [optional; defaults to exporting all objects]
# -a, --keep-aspect-ratio whether to preserve the aspect ratio [optional; defaults to FALSE]
# -b, --background-color=[black, white, #abccee, #aaa...] set the background color [optional; defaults to None]
# -s, --stylesheet Filename of CSS stylesheet
# -u, --unlimited Allow huge SVG files
# --keep-image-data Keep image data
# --no-keep-image-data Don't keep image data
# -v, --version show version information
brew cask install inkscape
inkscape --action-list
# action-list : Print a list of actions and exit.
# convert-dpi-method : Import DPI convert method.
# export-area : Export area.
# export-area-drawing : Export drawing area.
# export-area-page : Export page area.
# export-area-snap : Export snap area to integer values.
# export-background : Export background color.
# export-background-opacity: Export background opacity.
# export-do : Do export.
# export-dpi : Export DPI.
# export-filename : Export file name.
# export-height : Export height.
# export-id : Export id(s).
# export-id-only : Export id(s) only.
# export-ignore-filters: Export ignore filters.
# export-latex : Export LaTeX.
# export-margin : Export margin.
# export-overwrite : Export over-write file.
# export-pdf-version : Export PDF version.
# export-plain-svg : Export as plain SVG.
# export-ps-level : Export PostScript level.
# export-text-to-path : Export convert text to paths.
# export-type : Export file type.
# export-use-hints : Export using saved hints.
# export-width : Export width.
# file-close : Close active document.
# file-new : Open new document using template.
# file-open : Open file.
# inkscape-version : Print Inkscape version and exit.
# no-convert-baseline : Import convert text baselines.
# object-set-attribute: Set or update an attribute on selected objects. Usage: object-set-attribute:attribute name, attribute value;
# object-set-property : Set or update a property on selected objects. Usage: object-set-property:property name, property value;
# object-to-path : Convert shapes to paths.
# object-unlink-clones: Unlink clones and symbols.
# open-page : Import page number.
# query-all : Query 'x', 'y', 'width', and 'height'.
# query-height : Query 'height' value(s) of object(s).
# query-width : Query 'width' value(s) of object(s).
# query-x : Query 'x' value(s) of selected objects.
# query-y : Query 'y' value(s) of selected objects.
# quit-inkscape : Immediately quit Inkscape.
# select : Select by ID (Deprecated)
# select-all : Select all. Options: 'all' (every object including groups), 'layers', 'no-layers' (top level objects in layers), 'groups' (all groups including layers), 'no-groups' (all objects other than groups and layers, default).
# select-by-class : Select by class
# select-by-element : Select by SVG element (e.g. 'rect').
# select-by-id : Select by ID
# select-by-selector : Select by CSS selector
# select-clear : Selection clear
# select-invert : Invert selection. Options: 'all', 'layers', 'no-layers', 'groups', 'no-groups' (default).
# select-list : Print a list of objects in current selection.
# system-data-directory: Print system data directory and exit.
# transform-remove : Remove any transforms from selected objects.
# transform-rotate : Rotate selected objects by degrees.
# transform-scale : Scale selected objects by scale factor.
# transform-translate : Translate selected objects (dx,dy).
# unselect : Unselect by ID (Deprecated)
# unselect-by-id : Unselect by ID
# user-data-directory : Print user data directory and exit.
# vacuum-defs : Remove unused definitions (gradients, etc.).
# verb : Execute verb(s).
# verb-list : Print a list of verbs and exit.
# window-close : Close the active window.
# window-open : Open a window for the active document. GUI only.
inkscape --export-format="png" in.svg
npm install -g svgexport
svgexport infile.svg outfile.png
cairosvg
To-do.