I have Images stored on Grid/FS and in order to improve UI I want to resize all of them to fit within a certain dimension (stretching and squashing effect are outside of scope). Currently the images are returned using the following...
FileProvider.prototype.streamFile = function(res, _id, contenttype){
var properId = this.db.bson_serializer.ObjectID.createFromHexString(_id)
res.contentType(contenttype)
var readstream = gfs.createReadStream(properId, {
"content_type": contenttype,
"id":true,
"metadata":{
"author": "Jackie"
},
"chunk_size": 1024*4 })
readstream.pipe(res)
}
This works great but now I want to intercept the image and resize it so my idea was to stream it in-memory than preform a resize using imagemagik (If there is a better way please feel free to tell me).
However, the following code fails to load an image...
FileProvider.prototype.streamFile = function(res, _id, contenttype){
var properId = this.db.bson_serializer.ObjectID.createFromHexString(_id)
res.contentType(contenttype);
var readstream = gfs.createReadStream(properId, {
"content_type": contenttype,
"id":true,
"metadata":{
"author": "Jackie"
},
"chunk_size": 1024*4 });
var writestream = new stream.Stream()
writestream.writeable = true
writestream.write = function(data){
console.log("Streaming.."+data)
}
writestream.pipe = function(src){
console.log("Piping:"+src)
}
writestream.end = function (data){
console.log(JSON.stringify(data))
console.log("Completed")
}
readstream.pipe(writestream)
}
This outputs the following to the console...
undefined
Completed
In other words no data is getting written to the writeStream. Can anyone see what I am doing wrong?