npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

grunt-gm-picturefill

v0.0.4

Published

Plugin to crop or resize images to work with picturefill plugin or the picture element

Downloads

16

Readme

grunt-gm-picturefill

Plugin to resize images to work with picturefill plugin or the picture element providing sample output for easy reference

Picturefill by Scott Jehl

To find out how to use Picturefill on your sites, visit the project and demo site:

Picturefill Documentation, Downloads, and Demos Site

Getting Started

First download and install GraphicsMagick. In Mac OS X, you can simply use Homebrew and do:

brew install graphicsmagick

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-gm-picturefill --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-gm-picturefill');

The "gm_picturefill" task

Overview

In your project's Gruntfile, add a section named gm_picturefill to the data object passed into grunt.initConfig().

grunt.initConfig({
  gm_picturefill: {
    task_one: {
       options: {
          // Task-specific options go here.
        },
         files: {
          'path/to/dest/dir': ['path/to/source/one','path/to/source/two']
        }
    },
  },
})

Options

options.picturefill

Type: Object Default value:

[{
    breakpoint: '320px',
    prefix: 'xs',
    size: {
        width: 320,
        height: 320
    },
    quality: 100
}, {
    breakpoint: '768px',
    prefix: 'sm',
    size: {
        width: 768,
        height: 768
    },
    quality: 100
}, {
    breakpoint: '1024px',
    prefix: 'md',
    size: {
        width: 1024,
        height: 1024
    },
    quality: 100
}, {
    breakpoint: '1280px',
    prefix: 'lg',
    size: {
        width: 1280,
        height: 1280
    },
    quality: 100
}]

An Array of Objects having key/value pairs as follows

breakpoint

Type: String

The break point for which the images is to be resized eg. '40.063em' or '320px'.

prefix

Type: String

A string that uniquely identifies an image resized for a particular viewport size eg. 'xs' or 'small'.

If left '' (empty), the breakpoint will be added as the prefix.

size

Type: Object

An object containing width and height attributes used for resizing the images.

Note: Aspect ratio of the image will allways be maintained.

quality

Type: Number

The quality to be maintained for the resized images. Ranges from 0 to 100.

options.createSample

Type: Boolean

Default value: true

Flag to create the sample file containing the necessary markup to use the resized images with the Picturefill plugin.

options.sampleOutputPath

Type: String

Default value: './'

Path to the directory where the sample file will be created for reference.

Usage Examples

Default Options

grunt.initConfig({
  gm_picturefill: {
    default:{
      options: {},
      files: {
        'path/to/rsized': ['path/to/original']
      }
    }
  }
})

In this example, the default options are used to create resized images in the folder named resized from the folder original for the breakpoints 320px,768px,1024px and 1280px. So if there exists a file named sample.png in the original folder, then after the task is run it would create sample-xs.png,sample-sm.png,sample-md.png and sample-lg.png in the resized folder and create the following markup in the picturefill_sample directory.

<!--Picturefill element definition for file node-js -->
<picture>
  <!--[if IE 9]><video style="display: none;"><![endif]-->
    <source srcset="resized\sample-lg.png" media="(min-width: 1280px)">
    <source srcset="resized\sample-md.png" media="(min-width: 1024px)">
    <source srcset="resized\sample-sm.png" media="(min-width: 768px)">
  <!--[if IE 9]></video><![endif]-->
  
  <img srcset="resized\sample-xs.png" alt="Lorem ipsum dolor sit amet">
</picture>

Custom Options

grunt.initConfig({
  gm_picturefill: {
    custom:{
      options: {
        picturefill:[
          {
            breakpoint:'768px',
            size:{
              width:768,
              height:768
            }
            prefix:'small',
            quality:50
          },
          {
            breakpoint:'1280px',
            size:{
              width:1280,
              height:1280
            }
            prefix:'large',
            quality:100
          }
        ]
      },
      files: {
        'path/to/rsized': ['path/to/original']
      }
    }
  }
})

In this example, custom options are used to do create two resized images for the breakpoints 768px and 1280px with the prefix small and large respectively. So if there exists a file named sample.png in the original folder, then after the task is run it would create sample-small.png and sample-large.png in the resized folder and create the following markup in the picturefill_sample directory.

<!--Picturefill element definition for file node-js -->
<picture>
  <!--[if IE 9]><video style="display: none;"><![endif]-->
    <source srcset="resized\sample-large.png" media="(min-width: 1280px)">
  <!--[if IE 9]></video><![endif]-->
  
  <img srcset="resized\sample-small.png" alt="Lorem ipsum dolor sit amet">
</picture>

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release History

(0.0.4)

License

Copyright (c) 2014 Nisheed Jagadish. Licensed under the MIT license.