Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert external SVG file to inline SVG? #6

Open
ronnyandre opened this issue Feb 11, 2016 · 2 comments
Open

Convert external SVG file to inline SVG? #6

ronnyandre opened this issue Feb 11, 2016 · 2 comments
Labels

Comments

@ronnyandre
Copy link

Is it possible to load an external SVG resource into inline SVG?

@davidkpiano
Copy link
Owner

You would have to use a tool such as Sassport or Eyeglass, which allows JS interoperability with Sass. If there is enough interest, I can write a Sassport plugin, which would look like:

var fs = require('fs');
var sassport = require('sassport');

module.exports = sassport.module('svg')
  .functions({
    'inline-svg($file)': sassport.wrap(function(file) {
      return encodeURIComponent(fs.readFileSync(file));
    }
  });

And in the Sass:

@mixin svg-from($file) {
  background-image: url(#{ inline-svg($file) });
}

.foo {
  @include svg-from('my-svg-file.svg');
}

@fabiocaccamo
Copy link

fabiocaccamo commented Jun 7, 2016

Could you add the possibility to do something like this?

.foo {
    background-image:inline-svg('path/to/my-file.svg', fill='#ff0000', stroke='#000000');
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants