Retrieve image size information. The image-size port for grunt.
This plugin requires Grunt.
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:
npm install grunt-image-size --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-image-size');
This task produces a vector of an image size data from all provided source files:
[
{
name : 'path/to/file'
width : 100,
height : 100
},
...
]
And outputs it to grunt Config Data and/or to dest file (as json).
Type: String
Default: undefined
A string value that is used as a name for grunt config object for outputing data.
Type: Function
Default: undefined
Allows to alter name (file path) of each src
.
Will be invoked with injected values for following arguments:
src
— currentsrc
;file
—file
of currentsrc
.
this
will correspond to the current file
of the task.
Should return a String
.
Type: Function
Default: undefined
Allows to alter formed data of each src
.
Will be invoked with injected values for following arguments:
entry
— originalsrc
data;src
— file path of currentsrc
;file
—file
of currentsrc
.
this
will correspond to the current file
.
Should return an Object
.
Type: Function
Default: undefined
Allows to alter final data.
Result of this function will be used for printing Object to dest
file.
Will be invoked with injected values for following arguments:
sizes
— extracted and optionally processed final data;file
— currentfile
instance.
this
will correspond to the current file
of the task.
Should return whatever you want to print as a result.
Type: Function|String[]|Number[]
Default: null
Pass replacer parameter to JSON.stringify()
.
Type: String|Integer
Default: 2
Pass space parameter to JSON.stringify()
.
Controls indentation for outputted JSON file.
After processing all images from img/
script writes size information to image_data
config object and image_data.json file.
grunt.initConfig({
image_size: {
options: {
configObject : 'image_data'
},
files: [{
src : 'img/*',
dest : 'image_data.json'
}]
}
})
From image_data
it can be accessed with grunt.config.get('image_data')
or via template <%= image_data %>
Please, lint and test the code with npm test
before posting PRs.
Got some lint errors? Run npm run format
.
Tests failing? Fix the code to make them pass. Use npm run test:watch
for easier workflow.
Copyright (c) 2014 SAPer. Licensed under the MIT license.