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-blurred-images

v1.1.1

Published

Produce blurred versions of images. Used to reproduce Medium blur-on-scroll effect.

Downloads

3

Readme

grunt-blurred-images

Build Status Gitter

Produce blurred versions of images. Used to reproduce Medium blur-on-scroll effect.

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-blurred-images --save-dev

You also need to install either GraphicsMagick or Imagemagick CLI tools.

Installing GraphicsMagick (Recommended)

If you're a Mac user and have Homebrew installed, simply type:

brew install GraphicsMagick

Otherwise, please visit the GraphicsMagick downloads page.

Or installing ImageMagick

If you're a Mac user and have Homebrew installed, simply type:

brew install ImageMagick

Otherwise, please visit the ImageMagick downloads page.

Once both the plugin and graphics engine have been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-blurred-images');

The "blurred_images" task

Overview

The blurred_images task will take your source image and create images at the specified blur levels, allowing you to reproduce the Medium blur on scroll effect. See this article for more details about this effect.

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

grunt.initConfig({
  blurred_images: {
    options: {
      // Task-specific options go here.
    },
    your_target: {
      // Target-specific file lists and/or options go here.
    },
  },
})

Options

  • options.engine Type: String Default: gm Available Values: gm || im Version: 0.1.0 and above

    Chooses which graphics engine to use when blurring images. To use GraphicsMagick, set this to gm. To use ImageMagick, set this to im. You'll need the relevant engine installed.

  • options.newFilesOnly Type: Boolean Default: true Version: 0.1.0 and above

    Only process files that do not already exist in the destination folder. Note this is a rather basic check for whether to process files, it does not check timestamps or file data currently. This option is useful for making the task fast during development.

  • options.levels Type: Array Default: [{ name: 'low', level: 1 }, { name: 'medium', level: 4 }, { name: 'high', level: 8 }] Version: 0.1.0 and above

    An array of objects containing the levels and settings we want to blur our image.

    For example:

levels: [{ name: "low", level: 2 }, { name: "high", level: 10 }]


  The settings available are as follows:

  * **name**<br />
    *Type:* `String`<br />
    *Default:* none<br />
    *Version:* 0.1.0 and above

    If a `name` is specified, then the file will be suffixed with this name. e.g. `my-image-low.jpg`<br />
    If a `name` is not specified, then the file will be suffixed with the value specified in the level options. e.g. `my-image-1.jpg`

  * **rename**<br />
    *Type:* `Boolean`<br />
    *Default:* `true`<br />
    *Version:* 0.1.0 and above

    If `rename` is set to `false`, then at this level the file will not be renamed, but will instead keep its original name. Suffixes will still be applied.

  * **quality**<br />
    *Type:* `Number`<br />
    *Default:* `100`<br />
    *Available Values:* `1` - `100`<br />
    *Version:* 0.1.0 and above

    JPEG format only. The quality of the image, 100 being the highest quality and 1 being the lowest.

    Please note: In versions below 0.1.0, quality is specified between 0 and 1.

  * **suffix**<br />
    *Type:* `String`<br />
    *Default:* none<br />
    *Version:* 0.1.0 and above

    Use `suffix` to change filenames. e.g. `my-image-low_1.jpg`

* **options.separator**<br />
  *Type:* `String`<br />
  *Default:* `-`<br />
  *Version:* 0.1.0 and above

  The character used to separate the image filename from the level value.

### Usage Examples

#### Default Options
Using the default options will produce 3 blurred images - one at 1% blur, one at 5% blur and one at 9% blur.

```js
grunt.initConfig({
  blurred_images: {
    myTask: {
      options: {},
      files: {
        'dest/mario-yoshi.jpg': 'test/assets/mario-yoshi.jpg'
      }
    }
  }
})

Custom Options

In this example, we specify our own image blur levels. We also specify our files with a wildcard.

grunt.initConfig({
  blurred_images: {
    myTask: {
      options: {
        levels: [{
          name: 'low',
          level: 2
        }, {
          name: 'medium',
          level: 5
        }, {
          name: "high",
          level: 10,
          suffix: "xlarge",
          quality: 60
        }]
      },
      files: [{
        expand: true,
        src: ['assets/**.{jpg,gif,png}'],
        cwd: 'test/',
        dest: 'tmp/'
      }]
    }
  },
})

Custom Destination

If you would like to output each image level to a different directory, you can do so with custom_dest. For example:

grunt.initConfig({
  blurred_images: {
    myTask: {
      options: {
        levels: [{
          name: 'low',
          level: 2
        }, {
          name: 'medium',
          level: 5
        }, {
          name: "high",
          level: 10
          suffix: "xlarge",
          quality: 60
        }]
      },
      files: [{
        expand: true,
        src: ['**.{jpg,gif,png}'],
        cwd: 'test/assets/custom_dest/',
        custom_dest: 'tmp/custom_dest/{%= level %}/'
      }]
    }
  },
})

You can use {%= level %}, {%= name %} or {%= path %} as a delimiter.

Please note that {%= level %} and {%= name %} are only available if they are set in the object literal that you use to set each generated level option.

The {%= path %} value contains additional directory structure from the current working directory (cwd in files array) to each image. Using {%= path %} allows any complex directory structure to persist into the rendered blurred images directory.

NOTE: for grunt-blurred-images to pick up images within subdirectories you must set your files.src property to **/*.{jpg,gif,png}.

Acknowledgements

This module is based on the work of @andismith on grunt-responsive-images.

I am deeply thankful to this guy for his thorough work on grunt-responsive-images, which helped save a lot of time while developing grunt-blurred-images.