0
votes

On collectionfs I have following method to resize large images to width of 1200px and height remains proportional in order to reduce file size.

var createPic = function(fileObj, readStream, writeStream) {
    gm(readStream, fileObj.name()).resize(1200).quality(100).autoOrient().stream().pipe(writeStream);
}

Images with lets say 2000x2000 dimension actually end up uploaded 1200x1200 but larger in file size. Can you explain why? And how can I modify the method to only resize image if width exceeds for example 2000px?

1
Also, does anyone know how much facebook reduces photos in size and quality? Or do they use some kind of algorithm depending on image? - Zaya
Just a guess, but try resize("1200x1200>") in there. - Mark Setchell
That didn't resize at all and more than doubled the image file size. original image is 1919x1919 1.3mb. I had 1200x1200 1.8mb. With your guess it is 1919x1919 2.9mb - Zaya
Maybe resize('1200','1200>') - Mark Setchell
1200x1200 1.8mb. Can you explain the second argument. I assume this is the height. - Zaya

1 Answers

0
votes

This works:

gm(readStream, fileObj.name()).resize(1200, 1200, '>').quality(100).autoOrient().stream().pipe(writeStream);

However, after using it with the gridfs package you may get this error: Error: <ID> does not exist. This is a package's bug, so this topic would go separately.