@ampatspell/sofa-gm
v0.0.10
Published
gm wrapper for sofa/relax
Downloads
34
Readme
relax-gm
gm wrapper for @ampatspell/relax
Usage
var Sofa = require('@ampatspell/sofa');
var GM = require('@ampatspell/sofa-gm');
var sofa = new Sofa();
var gm = new GM();
sofa.register('image', function() {
this.props({
attachments: this.attachments('image_attachments'),
attachmentsInfo: this.attr(undefined, {serialize:false}),
});
});
var session = sofa.session(...);
var image = session.model('image', {id: 'one'});
var file = {
content_type: 'image/jpeg'
file: '/tmp/image.jpeg', // or Buffer
};
return gm.attach(image, file, [
['1024x1024', 1024, 1024, '>'],
['x400', null, 400, '>'],
['x200', null, 200, '>']
]).then(function(image) {
return image.save();
});
Saved document:
{
"_id": "one",
"_rev": "1-ec7883c7b29e142cf9f260cf63bf8ece",
"type": "image",
"attachments_info": {
"original": { "width": 1024, "height": 677 },
"1024x1024": { "width": 1024, "height": 677 },
"x400": { "width": 605, "height": 400 },
"x200": { "width": 303, "height": 200 }
},
"_attachments": {
"original": { "content_type": "image/jpeg", "length": 405026 },
"1024x1024": { "content_type": "image/jpeg", "length": 109260 },
"x400": { "content_type": "image/jpeg", "length": 61333 },
"x200": { "content_type": "image/jpeg", "length": 40771 }
}
}