Extract stroke and fill colors from SVG files. Designed for use in node, not the browser.
npm install get-svg-colors --save
const getColors = require("get-svg-colors")
// Give it an SVG filename
const colors = getColors(__dirname + '/australia.svg')
// Or an SVG string
const colors = getColors('<svg...>')
// You'll get back an object with two keys: `fills` and `strokes`
// `fills` is an array of chroma-js objects
colors.fills.map(color => color.hex())
// => ['#FFFFFF', '#123123', '#F0F0F0']
// `strokes` is also an array of chroma-js objects
colors.strokes.map(color => color.hex())
// => ['#FFFFFF', '#123123', '#F0F0F0']
// Crazy stuff...
colors.fills[0].alpha(0.5).css();
// => 'rgb(0,128,128)'
// Pass the `flat` option to get back a single array including
// de-duped fills and strokes together
const colors = getColors('<svg...>', {flat: true})
// => [...]
npm install
npm test
- cheerio: Tiny, fast, and elegant implementation of core jQuery designed specifically for the server
- chroma-js: JavaScript library for color conversions
- is-svg: Check if a String/Buffer is SVG
- lodash.compact: The modern build of lodash’s
_.compact
as a module. - lodash.uniq: The modern build of lodash’s
_.uniq
as a module.
- mocha: simple, flexible, fun test framework
ISC
Generated by package-json-to-readme