Compress profile pictures on upload

This commit is contained in:
Matthew Remmel
2025-09-15 08:40:02 -04:00
committed by hodlbod
parent fc3b68c390
commit 129f49bcc7
4 changed files with 43 additions and 27 deletions
+31
View File
@@ -135,3 +135,34 @@ export const scrollToEvent = async (id: string, attempts = 3): Promise<boolean>
return false
}
export const stripExifData = async (file, {maxWidth = null, maxHeight = null} = {}) => {
if (window.DataTransferItem && file instanceof DataTransferItem) {
file = file.getAsFile()
}
if (!file) {
return file
}
const {default: Compressor} = await import("compressorjs")
/* eslint no-new: 0 */
return new Promise((resolve, _reject) => {
new Compressor(file, {
maxWidth: maxWidth || 2048,
maxHeight: maxHeight || 2048,
convertSize: 10 * 1024 * 1024,
success: resolve,
error: e => {
// Non-images break compressor
if (e.toString().includes("File or Blob")) {
return resolve(file)
}
_reject(e)
},
})
})
}