feat: add profile and storage settings components, integrate rich text editor, and implement image compression for uploads

This commit is contained in:
Mo Tarbin
2025-05-27 02:18:59 -04:00
parent 81d3144da2
commit 6ddb8d01ec
14 changed files with 710 additions and 59 deletions

View File

@@ -0,0 +1,45 @@
// Utility to crop and resize an image to a square (e.g. 320x320) and return a JPEG Blob
// Usage: await getCroppedImg(imageSrc, croppedAreaPixels, width, height, mimeType)
export async function getCroppedImg(
imageSrc,
crop,
width,
height,
mimeType = 'image/jpeg',
) {
return new Promise((resolve, reject) => {
const image = new window.Image()
image.crossOrigin = 'anonymous'
image.onload = () => {
const canvas = document.createElement('canvas')
canvas.width = width
canvas.height = height
const ctx = canvas.getContext('2d')
// Draw the cropped image to the canvas
ctx.drawImage(
image,
crop.x,
crop.y,
crop.width,
crop.height,
0,
0,
width,
height,
)
canvas.toBlob(
blob => {
if (!blob) {
reject(new Error('Canvas is empty'))
return
}
resolve(blob)
},
mimeType,
0.92,
)
}
image.onerror = error => reject(error)
image.src = imageSrc
})
}