fotofoto

0.0.10 • Public • Published

fotofoto

Unofficial simple wrapper library for Flashfoto API http://flashfotoapi.com/. Every APIs return Promise.

Usage

npm install fotofoto

APIs:

var FF = require('fotofoto');
 
var ff = new FF({
  username : '[[YOUR USER NAME]]',
  apikey : '[[YOUR API KEY]]'
});
 
// Upload to server.
// See also http://flashfotoapi.com/docs/add
var data = fs.readFileSync('file/path/to/imagefile.jpg');
ff.add(data, {
  privacy : 'private'
}).then(function(result) {
  console.log(result);
}, function(err) {
  console.error(err);
});
 
// Get list of uploaded images.
// See also http://flashfotoapi.com/docs/find
ff.find().then(function(images) {
  console.log(images);
}, function(err) {
  console.error(err);
});
 
// Request segment processing.
// See also http://flashfotoapi.com/docs/segment
ff.segment('[[IMAGE_ID]]').then(function(res) {
  console.log(res);
}, function(err) {
  console.error(err);
});
 
// Check segment processing status.
// See also http://flashfotoapi.com/docs/segmentstatus
ff.segmentStatus('[[IMAGE_ID]]').then(function(status) {
  console.log(status);
}, function(err) {
  console.error(err);
});
 
// Get processed image.
// See also http://flashfotoapi.com/docs/get
ff.get('[[IMAGE_ID]]', {
  version : 'HardMasked'
}).then(function(image) {
  fs.writeFileSync('output.png', image);
}, function(err) {
  console.error(err);
});

Automated processing example

Upload, Request segment, wait, and get result images.

var fotofoto = require('fotofoto'),
    fs = require('fs');
 
var ff = new fotofoto({
  username : '[[YOUR NAME]]',
  apikey : '[[YOUR KEY]]'
});
 
var imageData = fs.readFileSync('test.jpg');
ff.add(imageData)
  .then(function(result) {
 
    console.log('add result', result);
 
    var id = result.Image.id;
 
    return ff.segment(id)
      .then(function(result) {
 
        console.log('segment result', result);
 
        return ff.waitForSegmentation(id);
 
      }).then(function() {
 
        return ff.info(id);
 
      }).then(function(info) {
 
        console.log('info result', info);
 
        // Save processed image
        var promises = info.ImageVersion.map(function(imgVer) {
 
          if (imgVer.version === 'HardMasked') {
 
            // save image to output.png
            return ff.get(id, {
              version: imgVer.version
            }).then(function(processedImage) {
              fs.writeFileSync('output-HardMasked.png', processedImage);
            });
          }
 
          return Promise.resolve();
        });
 
        return Promise.all(promises);
      });
  })
  .then(function() {
    console.log('END');
  });
 

See also official REST API documents

Readme

Keywords

Package Sidebar

Install

npm i fotofoto

Weekly Downloads

8

Version

0.0.10

License

MIT

Last publish

Collaborators

  • niusounds