Tutorial: Getting started

Getting started

The pattern is quite simple. You give a source file name and a set of transformations to the image transformer, and it will return you the transformed image after file caching it on the temp folder.

    
    var ImageTransformer = require('image-transform');

    var transformer = new ImageTransformer({
        path: './tmp/' // the temp folder path to be used as file cache
    });

    var transformations = [{
        type : "crop",
        options : {
            x : 74,
            y : 37,
            width : 352,
            height : 552
        }
    }, {
        type : "stretch",
        options : {
            width : 350,
            height : 350
        }
    }, {
        type : "fit",
        options : {
            width : 200,
            height : 200
        }
    }];

    transformer.transform('./image.jpg', transformations, function(err, info, image) {
        if(err)
            throw err;
            
        console.log('info', info); // some file info
        console.log('image', image); // the file stream
    });