img-crawler

A module to download images from a given URL

npm install img-crawler
4 downloads in the last week
10 downloads in the last month

img-crawler

A Node module for downloading images to disk from a given URL.

Installation

    npm install img-crawler

Running the tests

From the module directory run:

    npm test

Without npm:

    make test

Usage

Download imgs from 'pearljam.com' and write them to the 'pj-imgs' directory.
The dir will be created if not found and resolved to an absolute path.


     var crawler = require('img-crawler');

     var opts = {
         url: 'http://pearljam.com',
         dist: 'pj-imgs'
     };

     crawler.crawl(opts, function(err, data) {
         console.log('Downloaded %d from %s', data.imgs.length, opts.url);
     });

The callback

Keeping inline with node convention the callback first accepts an error object followed by data representing the downloaded images. The err object will be provided if loading the web page fails. Failures are reported in the img responses.

Here's an example of a response:

    {
        imgs: [
            {
                src: 'img/a-img.png', 
                statusCode: 200,
                success: true,
                path: '/Users/radvieira/my-imgs/img/a-img.png'
            },
            {
                src: 'img/another-img.png', 
                statusCode: 404,
                success: false
            }
] }

In this case the first image was downloaded and written to disk while the other failed. Notice how there is no path attribute for the failed download.

npm loves you