Skip to content
Small utility that automates the downsizing of retina assets
Find file
New pull request
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Retina Downsizer

Build Status

A small build utility based on node-imagemagick inclusive of command-line tool to fetch and resize retina suffixed (@2x) assets to different pixel densities in configurable and automated fashion.


npm install retina-downsizer

Usage examples


Import the module, intanciate it with some options and call run, if will run through the specified targets and generate downsized assets.

var RetinaDownsizer = require('retina-downsizer'),
    downsize = new RetinaDownsizer({
        targets: './'
    }); (err, generated) {
    if (err) { throw err; }

    // [ /absolute/path/foo.png, /absolute/path/bar.png, ... ]

Multiple targets

You can specify targets as an array, including names of image files and directories to be scanned recursively.

var RetinaDownsizer = require('retina-downsizer'),

new RetinaDownsizer({
    targets: [ './assets', './img/foo@2x.png' ]

Multiple densities

You can specify an array of custom densities (Relative to retina) to resize your retina assets to. Useful when serving your assets selectively with media-queries to many types of devices.

Custom densities will be saved with the same names, suffixed @x.x

var RetinaDownsizer = require('retina-downsizer'),

new RetinaDownsizer({
    targets: './',
    densities: [ 1, 1.5, 1.8 ]


  • targets (Default: './') - A string or array of strings containing directories and files to target
  • extensions (Default: [ 'png', 'jpg', 'jpeg', 'gif' ]) - Array of file extensions to target
  • log (Default: console.log) - Allows specifing a custom log/debug function
  • verbosity (Default: 2) - Level of verbosity. 0: Silent, 1: Log start and results, 2: Log each operation
  • depth (Default: 0) - Depth of range in the specified directory trees. Set to 0 will recur to every sub-directory
  • densities (Default: [ 1 ]) - Array of densities to resize assets to.

Command-line Tool


Install globally to use the command line tool

sudo npm install retina-downsizer - g


Run retinadownsizer --help

Downsize retina images.
Usage: retinadownsize

  -v, --verbose    Verbosity level. -v 0: Silent, -v 1: Log start and end, -v 2: (Default) Log each operation.
  -r, --recursive  Use to fetch and downsize all assets in a directory trees                                  
  -h, --help       Show usage info   

Test with nodeunit

You need to install nodeunit as a global dependency

sudo npm install -g nodeunit

Then run tests with

npm test


nodeunit test/tests
Something went wrong with that request. Please try again.