Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/saperio/grunt-image-size
grunt plugin for retrieve image size information
https://github.com/saperio/grunt-image-size
grunt-plugins image-size javascript
Last synced: about 2 months ago
JSON representation
grunt plugin for retrieve image size information
- Host: GitHub
- URL: https://github.com/saperio/grunt-image-size
- Owner: saperio
- Created: 2014-04-06T19:37:08.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2018-01-09T23:12:58.000Z (almost 7 years ago)
- Last Synced: 2024-10-07T18:48:55.277Z (3 months ago)
- Topics: grunt-plugins, image-size, javascript
- Language: JavaScript
- Size: 38.1 KB
- Stars: 2
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# grunt-image-size
Retrieve image size information. The [image-size](https://github.com/image-size/image-size) port for grunt.
## Getting Started
This plugin requires Grunt.
If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
```shell
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:
```js
grunt.loadNpmTasks('grunt-image-size');
```## The "image_size" task
### Overview
This task produces a vector of an image size data from all provided source files:
```js
[
{
name : 'path/to/file'
width : 100,
height : 100
},
...
]
```And outputs it to grunt Config Data and/or to dest file (as json).
### Options
#### options.configObject
Type: `String` Default: `undefined`
A string value that is used as a name for grunt config object for outputing data.
#### options.processName
Type: `Function` Default: `undefined`
Allows to alter name (file path) of each `src`.
Will be invoked with injected values for following arguments:
* `src` — current `src`;
* `file` — `file` of current `src`.`this` will correspond to the current `file` of the task.
Should return a `String`.
#### options.processEntry
Type: `Function` Default: `undefined`
Allows to alter formed data of each `src`.
Will be invoked with injected values for following arguments:
* `entry` — original `src` data;
* `src` — file path of current `src`;
* `file` — `file` of current `src`.`this` will correspond to the current `file`.
Should return an `Object`.
#### options.processSizes
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` — current `file` instance.`this` will correspond to the current `file` of the task.
Should return whatever you want to print as a result.
#### options.replacer
Type: `Function|String[]|Number[]` Default: `null`
Pass [replacer](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) parameter to `JSON.stringify()`.
#### options.space
Type: `String|Integer` Default: `2`
Pass [space](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) parameter to `JSON.stringify()`.
Controls indentation for outputted JSON file.
### Usage Examples
After processing all images from `img/` script writes size information to `image_data` config object and image_data.json file.
```js
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 %>`
### Development and testing
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.
## License
Copyright (c) 2014 SAPer. Licensed under the MIT license.