0.0.3 • Published 8 years ago

lwip-image-thumbnails-creator v0.0.3

Weekly downloads
5
License
Apache-2.0
Repository
github
Last release
8 years ago

lwip-image-thumbnails-creator

Create thumbnails from image using max width/height, optionnaly saving it to disk.

NPM version Build Status Dependency Status Coverage percentage

Install

$ npm install lwip-image-thumbnails-creator --save

Usage

Single thumbnail:

var thumbnailsCreator = require('lwip-image-thumbnails-creator');

var options = { outputbasepath: '/output/thumbnail.jpg'};

return thumbnailsCreator.createThumbnail('image.jpg', {
    maxWidth: 100,
    maxHeight: 50
}, options).then(function (res) {
    // ok
    console.log(res.thumbnail);
/* output:
    { 
        image: [Object], 
        width: 100, 
        height: 40, 
        maxWidth: 100, 
        maxHeight: 50, 
        outputpath: '/output/thumbnail-w150-h100.jpg' 
    }
*/

}, function (err) {
  // unexpected error
});

Multiple thumbnails:

return thumbnailsCreator.createThumbnail('image.jpg', [{
    maxWidth: 100,
    maxHeight: 50
},{
    maxWidth: 200,
    maxHeight: 100
}], options).then(function (res) {
    // ok
    console.log(res.thumbnails);
/* output:
    [ { 
        image: [Object], 
        width: 100, 
        height: 40, 
        maxWidth: 100, 
        maxHeight: 50, 
        outputpath: '/output/thumbnail-w100-h40.jpg' 
      }, ...]
*/
    
}, function (err) {
  // unexpected error
});

You can also have more control about what append with the thumbnail buffer by setting the saveToDisk to false, then using directly the lwip image object:

var options = {
    saveToDisk: false
};
var inputpath = path.resolve(__dirname, './images/original-image.jpg');

thumbnailsCreator.createThumbnail(inputpath, {
    maxWidth: 600,
    maxHeight: 300
}, options).then(function (res) {

var outputpath = path.resolve(__dirname, './images/output/thumbnail-exact-name.jpg');

res.thumbnail.image.writeFile(outputpath, function(err){
    // if (err) ...
});

Development

Logs

Simple log messages are managed using debugging utility

To display them, set env variable:

DEBUG=litc.*

Tests

Tests are run by Mocha test framework and Chai assertion library.

Test images are provided by EXIF Orientation-flag example images under MIT licence.

To run tests + coverage:

npm test

or

gulp

To run tests only

gulp test

To run tests in watch mode:

gulp test-auto

To enable logs:

 DEBUG=litc.* gulp test
 

Generator

Project generated with Yeoman Node Generator.

License

Apache-2.0 © Nicolas Toublanc

0.0.3

8 years ago

0.0.2

9 years ago

0.0.1

9 years ago