From d9a57aa2789eb922c4ca44975b5e874693f56002 Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Wed, 13 Apr 2016 12:52:30 +0200 Subject: [PATCH] Step 20.6: Resize images --- imports/api/images/store.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/imports/api/images/store.js b/imports/api/images/store.js index 58462c107..a0fa6d601 100644 --- a/imports/api/images/store.js +++ b/imports/api/images/store.js @@ -3,7 +3,19 @@ import { Images, Thumbs } from './collection'; export const ThumbsStore = new UploadFS.store.GridFS({ collection: Thumbs, - name: 'thumbs' + name: 'thumbs', + transformWrite(from, to, fileId, file) { + // Resize to 32x32 + const gm = require('gm'); + + gm(from, file.name) + .resize(32, 32) + .gravity('Center') + .extent(32, 32) + .quality(75) + .stream() + .pipe(to); + } }); export const ImagesStore = new UploadFS.store.GridFS({