I'm trying to do some cropping using graphicsmagick
and cfs
and save the result to S3 (cfs:gridfs, cfs:graphicsmagick and cfs:s3).
The cropped image should be stored to three stores (main, public and thumbnail) - the stores itself have some transformWrite
functions. So I thought I have to create a temp stream for doing this, but I failed to create this temp stream. I need some help for that.
I'm using the gridFS, no filesystem
var file = Media.findOne({ _id: fileId }),
read = file.createReadStream('main');
gmread = gm(read)
.crop(selection.w, selection.h, selection.x, selection.y)
.stream();
gmread.on('end', Meteor.bindEnvironment(function (error, result) {
if (error)
console.warn(error);
// create a temp stream
var tmpread = fs.createReadStream(filename); // <-- MY PROBLEM
tmpread.on('end', Meteor.bindEnvironment(function (error, result) {
if (error)
console.warn(error);
}));
// set cropped image to main store
var write = file.createWriteStream('main');
tmpread.pipe(write);
// set public store image
var writePublic = file.createWriteStream('public');
gm(tmpread).stream().pipe(writePublic);
// set thumbnail image
var writeThumbnail = file.createWriteStream('thumbnail');
gm(tmpread).stream().pipe(writeThumbnail);
}));
gmread.pipe(temp);