[FIX] Avatars with transparency were being converted to black (#13181)

pull/13194/head
Rodrigo Nascimento 6 years ago committed by GitHub
parent a2bdd3b8fd
commit dc2005b76d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      packages/rocketchat-file-upload/server/lib/FileUpload.js

@ -101,12 +101,20 @@ export const FileUpload = Object.assign(_FileUpload, {
metadata = {};
}
s.toFormat(sharp.format.jpeg)
.resize(Math.min(height || 0, metadata.width || Infinity), Math.min(height || 0, metadata.height || Infinity))
s.flatten({ background: '#FFFFFF' })
.jpeg()
.resize({
width: Math.min(height || 0, metadata.width || Infinity),
height: Math.min(height || 0, metadata.height || Infinity),
fit: sharp.fit.cover,
})
.pipe(sharp()
.resize(height, height)
.background('#FFFFFF')
.embed()
.resize({
height,
width: height,
fit: sharp.fit.contain,
background: '#FFFFFF',
})
)
// Use buffer to get the result in memory then replace the existing file
// There is no option to override a file using this library

Loading…
Cancel
Save