grunt-sharp
v0.16.0
Published
Resize JPEG, PNG, WebP and TIFF images.
Downloads
17
Readme
grunt-sharp
Resize JPEG, PNG, WebP and TIFF images.
Getting Started
This plugin requires Grunt ~0.4.0
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-sharp --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-sharp');
This plugin was designed to work with Grunt 0.4.x. If you're still using grunt v0.3.x it's strongly recommended that you upgrade, but in case you can't please use v0.3.2.
Sharp task
Run this task with the grunt sharp
command.
Task targets, files and options may be specified according to the grunt Configuring tasks guide.
Options
tasks
Type: Array
The list of tasks you want to run for an image. Each task is a set of transformations supported by sharp
.
If you only want to apply a single set of transformations, you can obviate the tasks
option and describe the transformations directly in the options
object.
Usage
To transform all images in a folder using a single set of transformation:
sharp: {
rotated: {
files: [{
expand: true,
cwd: 'src/images/',
src: ['**/*.png'],
dest: 'build/images/'
}],
options: {
background: 'white',
flatten: true,
resize: [48, 48],
rotate: 180
}
}
}
To apply multiple sets of transformations:
sharp: {
apple: {
files: [{
expand: true,
cwd: 'src/images/',
src: 'icon.png',
dest: 'build/images/'
}],
options: {
tasks: [
{resize: 64, rename: '{base}-32x32@2x.{ext}'},
{resize: 32, rename: '{base}-32x32.{ext}'},
{resize: 32, rename: '{base}-16x16@2x.{ext}'},
{resize: 16, rename: '{base}-16x16.{ext}'}
]
}
}
}
This task supports all the file mapping format Grunt supports. Please read Globbing patterns and Building the files object dynamically for additional details.
Meta
- Code:
git clone git://github.com/unindented/grunt-sharp.git
- Home: https://github.com/unindented/grunt-sharp/
Contributors
- Daniel Perez Alvarez ([email protected])
License
Copyright (c) 2015 Daniel Perez Alvarez (unindented.org). This is free software, and may be redistributed under the terms specified in the LICENSE file.