postcss-spritus
Find the sprites and then creates, saves and compresses
Easy to use with your CSS
The sprite is stored only those images that you use
For vanilla CSS or SCSS use gulp-css-spritus
Install
npm install postcss-spritus --save
Example
Input example
/* .icon-... */
Output example
/* .icon-... */
Methods and options
The path relative to the root of the script
;
Methods
Method | Description |
---|---|
spritus-url($sprite); |
is replaced by a relative link to the sprite url("../images/icons.png") |
spritus-size($sprite); |
is replaced with the size of the sprite |
spritus-position($sprite, "%file_name%"); |
is replaced by the position of the image in the sprite |
spritus-height($sprite, "%file_name%"); |
is replaced by height in pixels |
spritus-width($sprite, "%file_name%"); |
is replaced by width in pixels |
spritus:phw($sprite, "%file_name%"); |
is replaced by the position, height and width of the image in sprite background-position: 0px 60px;height:30px;width:30px; |
spritus:each($sprite); |
is replaced by all sprite image. See example below |
%file_name%
— may be full filename.png
or only basename filename
without extension
How does spritus:each($sprite);
In
/** example 1 **/ /** example 2 **/
Out
/** example 1 **//** example 2 **/
Inline options
;
- padding — see description in Plugin options
- algorithm — see description in Plugin options
- name — another name of the sprite to save
Plugin options
// ...// ...
padding
The amount of transparent space, in pixels, around each sprite. Defaults to 2
withImagemin
Compression of the sprite using imagemin. Defaults to true
withImageminPlugins
Specify what to use plugins for. Defaults to [require('imagemin-pngquant')({quality: "60-70",speed: 1})]
imageDirCSS
Relative URL (background-image) which is replaced in position in your CSS. Defaults to ../images/
imageDirSave
The path where to save the sprites relative to the root of the script. Defaults to public/images/
searchPrefix
If you want to use a different prefix, then this option is for you.
Defaults to spritus
gulpfile.js
// ...// ...
Now you can now use
algorithm
Images can be laid out in different fashions depending on the algorithm. We use layout to provide you as many options as possible. . Defaults to top-down
.At the time of writing, here are your options for algorithm
:
top-down |
left-right |
diagonal |
alt-diagonal |
binary-tree |
---|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
![]() |
More information can be found in the layout documentation: