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 🙏

© 2024 – Pkg Stats / Ryan Hefner

grunt-image-size

v1.0.0

Published

Retrieve image size information

Downloads

30

Readme

grunt-image-size

Retrieve image size information. The image-size port for grunt.

Getting Started

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');

The "image_size" task

Overview

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).

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;
  • filefile 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;
  • filefile 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 parameter to JSON.stringify().

options.space

Type: String|Integer Default: 2

Pass space 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.

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.