Skip to content
Extract stroke and fill colors from SVG files
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test
.travis.yml
README.md update repository url Apr 14, 2018
example.js
index.js Add check for stop-color in inline styles Nov 10, 2017
package.json

README.md

get-svg-colors

Extract stroke and fill colors from SVG files. Designed for use in node, not the browser.

Installation

npm install get-svg-colors --save

Usage

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})
// => [...]

Tests

npm install
npm test

Dependencies

  • 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.

Dev Dependencies

  • mocha: simple, flexible, fun test framework

License

ISC

Generated by package-json-to-readme

You can’t perform that action at this time.