{ const files = profileImageInputElement.files ?? []; let reader = new FileReader(); reader.onload = (event) => { let originalImageUrl = `${event.target.result}`; const img = new Image(); img.src = originalImageUrl; img.onload = function () { const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); // Calculate the aspect ratio of the image const aspectRatio = img.width / img.height; // Calculate the new width and height to fit within 250x250 let newWidth, newHeight; if (aspectRatio > 1) { newWidth = 250 * aspectRatio; newHeight = 250; } else { newWidth = 250; newHeight = 250 / aspectRatio; } // Set the canvas size canvas.width = 250; canvas.height = 250; // Calculate the position to center the image const offsetX = (250 - newWidth) / 2; const offsetY = (250 - newHeight) / 2; // Draw the image on the canvas ctx.drawImage(img, offsetX, offsetY, newWidth, newHeight); // Get the base64 representation of the compressed image const compressedSrc = canvas.toDataURL('image/jpeg'); // Display the compressed image profileImageUrl = compressedSrc; profileImageInputElement.files = null; }; }; if ( files.length > 0 && ['image/gif', 'image/webp', 'image/jpeg', 'image/png'].includes(files[0]['type']) ) { reader.readAsDataURL(files[0]); } }} />
{ profileImageInputElement.click(); }} >
{$i18n.t('Profile Image')}
{ if (canvasPixelTest()) { profileImageUrl = generateInitialsImage(name); } else { toast.info( $i18n.t( 'Fingerprint spoofing detected: Unable to use initials as avatar. Defaulting to default profile image.' ), { duration: 1000 * 10 } ); } }}>{$i18n.t('Use Initials')}
{ const url = await getGravatarUrl($user.email); profileImageUrl = url; }}>{$i18n.t('Use Gravatar')}
{ profileImageUrl = '/user.png'; }}>{$i18n.t('Remove')}
{$i18n.t('Name')}
{$i18n.t('API keys')}
{ showAPIKeys = !showAPIKeys; }}>{showAPIKeys ? $i18n.t('Hide') : $i18n.t('Show')}
{#if showAPIKeys}
{$i18n.t('JWT Token')}
{ copyToClipboard(localStorage.token); JWTTokenCopied = true; setTimeout(() => { JWTTokenCopied = false; }, 2000); }} > {#if JWTTokenCopied}
{:else}
{/if}
{$i18n.t('API Key')}
{#if APIKey}
{ copyToClipboard(APIKey); APIKeyCopied = true; setTimeout(() => { APIKeyCopied = false; }, 2000); }} > {#if APIKeyCopied}
{:else}
{/if}
{ createAPIKeyHandler(); }} >
{:else}
{ createAPIKeyHandler(); }} >
{$i18n.t('Create new secret key')}
{/if}
{/if}
{ const res = await submitHandler(); if (res) { saveHandler(); } }} > {$i18n.t('Save')}