imgseeker

Finding an image for a given URL

imgseeker

Finding an image for a given URL. imgseeker uses OpenGraph og:image as a fallback if no config for the hostname is given and og:image exists.

Install the module with: npm install imgseeker

var imgseeker = require('imgseeker');
imgseeker.init({});
imgseeker.seek('http://www.some-domain.com/some/path/index.html', function (err, imgUrl)) {
  // do something with imgUrl
});
  • maxConnections: Number, Size of the worker pool (Default 10)
  • defaultImg: Boolean, indicates if at least the first img on the page should be returned (Default true)

IMPORTANT: You need to call the init-method () before seeking in an URL. The init-method itself is chainable so you can call imgseeker.init().seek(…

if no config for a hostname is given, imgseeker tries to fetch OpenGraphs og:image, if there is no og:image it tries to fetch the first image of the page (if defaultImg is set to true)

var imgseeker = require('imgseeker');
imgseeker.init(); // setting the global config
imgseeker.seek('some-url', function (err, imgUrl) {
  // do something with imgUrl
});
imgseeker.seek('some-url', {'some-url': '.img-class'}function (err, imgUrl) {
  // do something with imgUrl
});
// init and seek with global config (including maxConnections)
var imgseeker = require('imgseeker');
imgseeker.init({
  maxConnections: 50,
  'www.some-domain.com': '.some-class > img',
  'another-domain.com': 'img'
}).seek('http://www.some-domain.com/some/path/index.html', function (err, imgUrl)) {
  // do something with imgUrl
});
 
// seek with special config (which overrides global config)
var specialConfig = {
  'www.some-domain.com': '.some-special-selector'
};
imgseeker.seek('http://www.some-domain.com/some/path/index.html', specialConfig,function (err, imgUrl)) {
  // do something with imgUrl
});

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

  • 0.1.0
    • Initial Commit
  • Bastian "hereandnow" Behrens

Copyright (c) 2013 Valiton GmbH Licensed under the MIT license.