feat(communication): add chat reactions emojis and images

This commit is contained in:
2026-10-03 17:56:07 +02:00
parent 59538f46b7
commit 29a9ec2242
25 changed files with 737 additions and 57 deletions

View File

@@ -0,0 +1,16 @@
export async function prepareChatImage(file) {
if (!['image/jpeg', 'image/png', 'image/webp'].includes(file.type)) throw new Error('Bitte ein JPEG-, PNG- oder WebP-Bild auswählen.')
if (file.size > 10 * 1024 * 1024) throw new Error('Das Originalbild darf höchstens 10 MB groß sein.')
const bitmap = await createImageBitmap(file)
try {
const scale = Math.min(1, 1600 / Math.max(bitmap.width, bitmap.height))
const canvas = document.createElement('canvas')
canvas.width = Math.max(1, Math.round(bitmap.width * scale)); canvas.height = Math.max(1, Math.round(bitmap.height * scale))
canvas.getContext('2d').drawImage(bitmap, 0, 0, canvas.width, canvas.height)
for (const quality of [0.85, 0.7, 0.55, 0.4]) {
const dataUrl = canvas.toDataURL('image/webp', quality)
if (dataUrl.length <= 480_000) return { dataUrl, name: (file.name || 'Bild').slice(0, 200) }
}
throw new Error('Dieses Bild ist zu groß. Bitte einen kleineren Ausschnitt verwenden.')
} finally { bitmap.close() }
}