Resize images for thumbnails in CollectionFS using Jimp
This package assumes you're using CollectionFS.
meteor add numtel:cfs-image-resize
A resizeImageStream
function is exposed when this package is installed. Call this function with options for resizing.
Only image/png
and image/jpeg
file types are supported.
Images will be centered if the aspect ratio between the input and the output differs.
Images = new FS.Collection("images", {
stores: [
new FS.Store.GridFS("images"),
new FS.Store.GridFS("thumbs", {
beforeWrite: function(fileObj) {
// We return an object, which will change the
// filename extension and type for this store only.
return {
extension: 'jpeg',
type: 'image/jpeg'
};
},
transformWrite: resizeImageStream({
width: 100,
height: 50,
format: 'image/jpeg',
quality: 50
})
})
],
});
Option | Description |
---|---|
width |
Output width in pixels, required |
height |
Output height in pixels, required |
format |
Format of output image, optional, default same as input, accepts image/png or image/jpeg |
quality |
Output image quality number 0-100, only used with JPEG images, optional |
Although images are resized in a separate process to prevent the event loop from being blocked, large images will take significant time to resize due to the JavaScript implementation of the image encoders and decoders.
For high load situations where more capacity is needed, look into using GraphicsMagick using the cfs:graphicsmagick
Package.
Use the standard command:
meteor test-packages ./
MIT