SMPT, SMS, Rejestracja + GUS

This commit is contained in:
2026-08-09 21:12:16 +02:00
parent a0c9d7947b
commit c464c5f708
78 changed files with 5841 additions and 258 deletions
+27
View File
@@ -0,0 +1,27 @@
// Wspoldzielone narzedzia do obrazow (kompresja przy wgrywaniu).
/**
* Kompresja obrazu przy wgrywaniu: jesli szerokosc przekracza maxWidth, skalujemy do maxWidth
* (proporcjonalnie), inaczej zostawiamy oryginalny rozmiar. Zwraca dataURL JPEG. Gdy cos zawiedzie,
* wraca obiektowy URL oryginalu, zeby dodawanie zdjec zawsze dzialalo.
*/
export async function compressImageFile(file: File, maxWidth = 1024, quality = 0.82): Promise<string> {
try {
const bitmap = await createImageBitmap(file);
const scale = Math.min(1, maxWidth / bitmap.width);
const width = Math.max(1, Math.round(bitmap.width * scale));
const height = Math.max(1, Math.round(bitmap.height * scale));
const canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext('2d');
if (!ctx) {
return URL.createObjectURL(file);
}
ctx.drawImage(bitmap, 0, 0, width, height);
bitmap.close();
return canvas.toDataURL('image/jpeg', quality);
} catch {
return URL.createObjectURL(file);
}
}