Git Product home page Git Product logo

get-svg-colors's Introduction

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

get-svg-colors's People

Contributors

danielbrodin avatar dependabot-support avatar dependabot[bot] avatar ionicabizau avatar zeke avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.