项目作者: yoksel

项目描述 :
Resize and color svg-images
高级语言: HTML
项目地址: git://github.com/yoksel/grunt-svg-modify.git
创建时间: 2014-08-24T19:36:44Z
项目社区:https://github.com/yoksel/grunt-svg-modify

开源协议:MIT License

下载


[NOT SUPPORTED] grunt-svg-modify

Resize and color svg-images

Modify SVG by JSON.

Getting Started

This plugin requires Grunt ~0.4.5

If you haven’t used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you’re familiar with that process, you may install this plugin with this command:

  1. npm install grunt-svg-modify --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

  1. grunt.loadNpmTasks('grunt-svg-modify');

Usage

The “svg_modify” Task:

  1. grunt.initConfig({
  2. svg_modify: {
  3. options: {
  4. // global options
  5. },
  6. your_target: {
  7. cwd: "cwd/", // <--- Folder with sources and results
  8. src: "sources/", // <--- Subfolders will be processed too
  9. dest: "result/", // <--- All processed folders wiil be placed here
  10. options: {
  11. // your_target specific options
  12. }
  13. }
  14. }
  15. });

options.previewFile

Type: Boolean
Default value: "true"

Choose whether or not you want to create and open a preview html file

Configure with json:

Create config.json and place it to the folder with your SVG-images.

Variations of config.json see below:

Colorize:

For transparent images only!

If SVG-element has fills, these fills will not be replaced.

  1. {
  2. "defaultColor": "hotpink"
  3. }

Resize and colorize images (without renaming):

  1. {
  2. "defaults": {
  3. "arrow-up": {
  4. "width": "200" // <--- height will be setted automatically
  5. },
  6. "home": {
  7. "height": "50", // <--- width will be setted automatically
  8. "color": "skyblue" // <--- this override 'defaultColor'
  9. }
  10. }
  11. }

Make variations of one file:

  1. {
  2. "variations": {
  3. "arrow-up": [{
  4. "width": "40" // ---> arrow-up--w40.svg
  5. }, {
  6. "height": "120",
  7. "color": "orange" // ---> arrow-up--h120--orange.svg
  8. }, {
  9. "color": "gold" // ---> arrow-up--gold.svg
  10. }],
  11. "home": [{
  12. "width": "100" // ---> home--w100.svg
  13. }, {
  14. "height": "70",
  15. "color": "pink" // home--h100--pink.svg
  16. }, {
  17. "color": "yellowgreen" // ---> home--yellowgreen.svg
  18. }]
  19. }
  20. }

Combo (all modifications in one file):

  1. {
  2. "defaultColor": "blue", // <--- Set color
  3. "defaults": { // <--- 1. Defaults will be processed first
  4. "home": {
  5. "width": "123"
  6. },
  7. "remove": {
  8. "height": "32",
  9. "color": "teal"
  10. }
  11. },
  12. "variations": { // <--- 2. Then will be processed variations
  13. "arrow-up": [{
  14. "width": "40"
  15. }, {
  16. "width": "120",
  17. "color": "gold"
  18. }, {
  19. "color": "yellow"
  20. }],
  21. "home": [{
  22. "width": "100"
  23. }, {
  24. "width": "70",
  25. "color": "crimson"
  26. }, {
  27. "width": "20",
  28. "color": "gray"
  29. }, {
  30. "color": "green"
  31. }]
  32. }
  33. }

Release History

0.0.7 - Added options & option to not create / open preview file

0.0.4 - Now fill color correctly overrides by config