elad / node-imagemagick-native

ImageMagick's Magick++ bindings for NodeJS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

New pipeline like api

cartuchogl opened this issue · comments

Working on support for im7, I have found that the current c++ code is quite hard to extend with new functionalities. I have worked a bit on a new way of exposing the options that I think is less hard to be extended.

At the javascript level it looks like a pipeline api like:

imagemagick.image(srcData)
  .resize({ width: 150, height: 150 })
  .blur(5)
  .flip()
  .rotate(90)
  .composite({ srcData: srcData, gravity: 'NorthGravity', op: 'OverCompositeOp' })
  .flip()
  .outFormat('png')
  .exec(function (err, buffer) {
    ...
  });

At the library level each command extends the ImCommandWrapper class

// .rotate(90) command
class ImRotateCommand : public ImCommandWrapper {
public:
    bool loadConfig(Local<Object> v) {
        this->degrees = v->IsUndefined() ? 0 : v->Int32Value();
        return true;
    };

    bool execute(Magick::Image *image) {
        image->rotate(this->degrees);
        return true;
    };
private:
    int degrees = 0;
};

The current state is in https://github.com/cartuchogl/node-imagemagick-native/tree/pipeline

TODO:

  • Documentation
  • True testing

Any feedback are wellcome.