Resize JPEG, PNG, WebP and TIFF images.
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
tasks
test Take extDot option into account Jan 25, 2015
.gitignore
.jscsrc
.jsfmtrc
.jshintrc Update linting configuration Jan 26, 2016
.npmignore Tweak npmignore file Feb 20, 2016
.travis.yml Release from Travis Feb 20, 2016
Gruntfile.js
LICENSE Declare use of MIT license in package Jul 19, 2015
README.md
package.json Bump version to v0.16.0 Aug 24, 2016

README.md

grunt-sharp Version Build Status Dependency Status

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

Contributors

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.