项目作者: attitude

项目描述 :
Generates inline SVGs [devtool]
高级语言: PHP
项目地址: git://github.com/attitude/inline-svg.git
创建时间: 2020-12-07T11:27:05Z
项目社区:https://github.com/attitude/inline-svg

开源协议:MIT License

下载


Inline SVG

Generates CSS (or Less CSS) file with embeded SVG icons. No SVG fragments = IE 11 should work fine.

The only dependency is PHP. It’s much faster for me to write terminal script than Shell scripts…

Prerequisites:

  • Monochrome icons, with single color fills and/or strokes
  • No optimisations — optimise before runnig (SVGo, Image Optim app,…)
  • Encoded without Base 64 to safe some bytes

Caveat:\
To be able to use different colour icons, every color variation needs to be
included in the final CSS.

Less mixins by default have 2 parameters:

  • @fill — no default value, needs to be specified when calling mixin
  • @stroketransparent by default

See --template option for details.

About

Inspired by: https://github.com/tigt/mini-svg-data-uri/blob/master/index.js

Read more:


Install using composer

  1. {
  2. "name": "you/example-project",
  3. "repositories": [
  4. {
  5. "type": "vcs",
  6. "url": "https://github.com/attitude/inline-svg"
  7. }
  8. ],
  9. "require": {
  10. "attitude/inline-svg": "dev-main"
  11. }
  12. }

Usage

  1. $ composer inline-svg [options]

or when cloned directrly:

  1. $ ./inline-svg dir/with/svgs/ output.file [options]

Example:

  1. $ ./inline-svg images/icons styles/icons.less --backup=false --comment='// out: false, main: styles.less'

Command line options

-b
--backup

Creates a backup of the target file

values: true \ false
default: true
example: -b=false

-r
--replace-colors=false

Replace colours with Less CSS variables used with mixin template

Generates Less CSS mixins with parameters to override SVG color and stroke. Requires .less extension. This script simply replaces all fill/stroke colors with variables when set true.

values: true \ false
default: true when target file specifies .less extension
default: false when target file specifies .css extension

-t
--template

Template for the CSS class definition

Expects two %s placeholders, first for the icon name, second for the SVG background-color style.

value: string
default: for .css file targets:
  1. .icon-%s { background-image: url(\”data:image/svg+xml,%s\”) }
default: for .less file targets:
  1. .icon-%s-mixin(@fill, @stroke: transparent) { @fill: replace(@fill, ‘#’, ‘%%23’); @stroke: replace(@stroke, ‘#’, ‘%%23’); background-image: url(\”data:image/svg+xml,%s\”) }
default: when --replace-colors=false:
  1. .icon-%s() { background-image: url(\”data:image/svg+xml,%s\”) }

-c
--comment

Adds any comment before the CSS output

value: string
default: ''
example: --comment='// out: false, main: styles.less'

-n
--new-line

New line at the end of the file
values: | true | false
—————|:-
default: | true
example: | --new-line=false


. . .


✨ Enjoy!

@martin_adamko">Martin