Gathering detailed insights and metrics for grunt-sprite-packer
Gathering detailed insights and metrics for grunt-sprite-packer
Gathering detailed insights and metrics for grunt-sprite-packer
Gathering detailed insights and metrics for grunt-sprite-packer
A grunt plugin that converts multiple png files into single sprite file using efficient packer algorithm.
npm install grunt-sprite-packer
Typescript
Module System
Min. Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
11 Stars
23 Commits
5 Forks
2 Watchers
1 Branches
3 Contributors
Updated on Apr 06, 2017
Latest Version
0.1.7
Package Id
grunt-sprite-packer@0.1.7
Size
6.90 kB
NPM Version
1.4.14
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
1
4
Sprite packer converts multiple png files into single sprite file using efficient packer algorithm. Metadata (names, dimensions and positions of individual sprites) are written into separate template-based text file.
This plugin requires Grunt ~0.4.1
and ImageMagick library.
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:
1npm install grunt-sprite-packer --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
1grunt.loadNpmTasks('grunt-sprite-packer');
ImageMagick library have to be installed in your system. See www.imagemagick.org for installation instructions.
This task converts multiple images into single image using efficient packing algorithm. It outputs two files: resulting sprite image and a text file with information about positions and dimensions of individual sprites. This text file has no fixed format or structure, instead it is generated using a handlebars template, so that you have full control of its format. It can be plain CSS with classes or some declarations for additional processing (LESS, SASS, Stylus or JSON).
NEW: Since version 0.1.7, Spritepacker can now work with SVG files. See svg option for details. This is an experimental feature, please report any issues you may encounter.
In your project's Gruntfile, add a section named spritepacker
to the data object passed into grunt.initConfig()
.
1grunt.initConfig({
2 spritepacker: {
3 default_options: {
4 options: {
5 // Path to the template for generating metafile:
6 template: 'css/sprites.css.tpl',
7
8 // Destination metafile:
9 destCss: 'css/sprites.css',
10
11 // Base URL for sprite image, used in template
12 baseUrl: '../img/'
13 },
14 files: {
15 'img/sprites.png': ['img/sprites/*.png']
16 }
17 }
18 }
19})
Type: String
A path to the template for generating metafile. Template is processed through Handlebars with the following variables:
sprites
- an array of object with metainfo for each spritebaseUrl
- base URL from task optionsfileName
- file name of generated sprite file (i.e. task destination)width
- width of generated sprite fileheight
- height of generated sprite filetimestamp
- timestamp (can be used in template as image url parameter to prevent caching issues) - deprecated, use checksum insteadchecksum
- md5 hash of the generated sprite image file (can be used in template as image url parameter to prevent caching issues)Each item in sprites array contains the following properties:
name
- name of the sprite (= original file name without extension)x
- x position of the sprite in generated sprite filey
- y position of the sprite in generated sprite filewidth
- width of the spriteheight
- height of the spriteExample of template file for generating simple CSS:
{{#sprites}}.{{name}} = { background: url('{{../baseUrl}}{{../fileName}}') no-repeat -{{x}}px -{{y}}px; width: {{width}}px; height: {{height}}px; }
{{/sprites}}
Example of template file for generating Stylus declarations to be processed later by some Stylus function:
{{#sprites}}{{name}} = ('{{../baseUrl}}{{../fileName}}' -{{x}}px -{{y}}px {{width}}px {{height}}px {{../name}})
{{/sprites}}
Type: String
A path to the template file.
Type: String
A path to the metafile that will be generated from the template.
Type: String
URL path to the generated sprite file.
Type: Number
Default: 0
White space that will be added as a padding around every sprite (in px). It is useful to prevent bleeding pixels from one sprite to another when scaled / interpolated in the browser.
Type: String
Default: 'png32'
Output file format. Any image format supported by ImageMagick should work (tested 'png32'
and 'jpg'
).
Type: String
Default: 'none'
Background color of output image. 'none'
= transparent, '#ffffff'
= white, '#ff0000'
= red etc.
Type: String
Default: '100%'
Compression quality of output file. Has no effect for file formats other than jpg.
Type: Boolean
Default: false
When set to true
, dimensions of sprites will be aligned to even pixels (useful when scaled down by factor of 2 in CSS for mobile/retina/nonretina optimization). Note that padding must be set to (multiple of) 2 as well.
Type: Boolean
Default: false
Version: 0.1.7
When set to true
, the packer will work in experimental SVG mode. In this mode, all of the input sprites have to be valid SVG files. These SVGs will be merged into a single SVG sprite file by some XML processing. Individual sprites will be included as SVG elements (SVG root element can contain another SVG elements) and positioned using the same packer algorithm as in normal "bitmap" mode. Note that each SVG sprite should have correctly set width
and height
attributes that define its bounding box. The viewBox
attribute is ignored. To prevent problems with duplicate ID attributes from different files, any IDs are prefixed with the name of the sprite. All xlink:href
and url(#)
references are modified accordingly.
This plugin uses binary tree packer algorithm by Jake Gordon (https://github.com/jakesgordon/bin-packing/).
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 3/22 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More