I'm using meteor(which is built on node) and CollectionCFS(which allows me to use gm[GraphicsMagick] for thumb-nailing).
I do the following to have it automaticly create a thumbnail of uploaded images:
new FS.Store.FileSystem("thumbs", {
transformWrite: function(fileObj, readStream, writeStream) {
gm(readStream, fileObj.name()).resize('100', '100').stream().pipe(writeStream);
},
path: "/Volumes/Public/Thumbs",
})
The transformWrite function receives the readStream(the original image), modifies it and pipes the results to the writeStream. How could I have it create thumbnails of PDF's?
If you just want the pdf's first page as thumbnail. do the following:
new FS.Store.FileSystem("thumbs", {
transformWrite: function(fileObj, readStream, writeStream) {
gm(readStream, fileObj.name() + '[0]').resize('100', '100').stream('png').pipe(writeStream);
},
beforeWrite: function (fileObj) {
return {
extension: 'png',
type: 'image/png'
};
},
path: "/Volumes/Public/Thumbs",
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With