{ let reader = new FileReader(); reader.onload = async (event) => { let originalImageUrl = `${event.target.result}`; let character = await parseFile(inputFiles[0]).catch((error) => { return null; }); console.log(character); if (character && character.character) { character = character.character; console.log(character); name = character.name; const pattern = /<\/?[a-z][\s\S]*>/i; if (character.summary.match(pattern)) { const turndownService = new TurndownService(); info.meta.description = turndownService.turndown(character.summary); } else { info.meta.description = character.summary; } info.params.system = `Personality: ${character.personality}${ character?.scenario ? `\nScenario: ${character.scenario}` : '' }${character?.greeting ? `\First Message: ${character.greeting}` : ''}${ character?.examples ? `\nExamples: ${character.examples}` : '' }`; } 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 100x100 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(); // Display the compressed image info.meta.profile_image_url = compressedSrc; inputFiles = null; }; }; if ( inputFiles && inputFiles.length > 0 && ['image/gif', 'image/webp', 'image/jpeg', 'image/png', 'image/svg+xml'].includes( inputFiles[0]['type'] ) ) { reader.readAsDataURL(inputFiles[0]); } else { console.log(`Unsupported File Type '${inputFiles[0]['type']}'.`); inputFiles = null; } }} />
{ submitHandler(); }} >
{$i18n.t('Name')}*
{$i18n.t('Model ID')}*
{$i18n.t('Base Model (From)')}
{$i18n.t('Description')}
{#if info.meta.description !== null}