fixed issue that caused exception when validating avatars with invalid metadata

pull/11009/head
Pierre 8 years ago
parent e18cc8923e
commit f7bf6e7383
  1. 7
      packages/rocketchat-file-upload/server/lib/FileUpload.js

@ -91,9 +91,14 @@ Object.assign(FileUpload, {
s.rotate();
// Get metadata to resize the image the first time to keep "inside" the dimensions
// then resize again to create the canvas around
s.metadata(Meteor.bindEnvironment((err, metadata) => {
if (!metadata) {
metadata = {};
};
s.toFormat(sharp.format.jpeg)
.resize(Math.min(height, metadata.width), Math.min(height, metadata.height))
.resize(Math.min(height || 0, metadata.width || Infinity), Math.min(height || 0, metadata.height || Infinity))
.pipe(sharp()
.resize(height, height)
.background('#FFFFFF')

Loading…
Cancel
Save