Retina Downsizer
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.
Installation
npm install retina-downsizer
Usage examples
Usage
Import the module, intanciate it with some options and call run
, if will run through the specified targets and generate downsized assets.
var RetinaDownsizer = downsize = targets: './' ; downsize;
Multiple targets
You can specify targets as an array, including names of image files and directories to be scanned recursively.
var 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 = targets: './' densities: 1 15 18 ;
Options
targets
(Default:'./'
) - A string or array of strings containing directories and files to targetextensions
(Default:[ 'png', 'jpg', 'jpeg', 'gif' ]
) - Array of file extensions to targetlog
(Default:console.log
) - Allows specifing a custom log/debug functionverbosity
(Default:2
) - Level of verbosity.0
: Silent,1
: Log start and results,2
: Log each operationdepth
(Default:0
) - Depth of range in the specified directory trees. Set to0
will recur to every sub-directorydensities
(Default:[ 1 ]
) - Array of densities to resize assets to.
Command-line Tool
Installation
Install globally to use the command line tool
sudo npm install retina-downsizer - g
Usage
Run retinadownsizer --help
Downsize retina images.
Usage: retinadownsize
Options:
-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
Test as a local dependency
npm test retina-downsize
Test as a global dependency
sudo npm test retina-downsizer -g