diff --git a/public/scripts/extensions/shared.js b/public/scripts/extensions/shared.js index 37dbec96a..26164d8d0 100644 --- a/public/scripts/extensions/shared.js +++ b/public/scripts/extensions/shared.js @@ -23,7 +23,7 @@ export async function getMultimodalCaption(base64Img, prompt) { const compressionLimit = 2 * 1024 * 1024; if (extension_settings.caption.multimodal_api === 'openrouter' && base64Bytes > compressionLimit) { const maxSide = 1024; - base64Img = await createThumbnail(base64Img, maxSide, maxSide); + base64Img = await createThumbnail(base64Img, maxSide, maxSide, 'image/jpeg'); } const apiResult = await fetch('/api/openai/caption-image', { diff --git a/public/scripts/utils.js b/public/scripts/utils.js index d8b99956f..571583240 100644 --- a/public/scripts/utils.js +++ b/public/scripts/utils.js @@ -973,9 +973,10 @@ export function loadFileToDocument(url, type) { * @param {string} dataUrl The data URL encoded data of the image. * @param {number} maxWidth The maximum width of the thumbnail. * @param {number} maxHeight The maximum height of the thumbnail. + * @param {string} [type='image/jpeg'] The type of the thumbnail. * @returns {Promise} A promise that resolves to the thumbnail data URL. */ -export function createThumbnail(dataUrl, maxWidth, maxHeight) { +export function createThumbnail(dataUrl, maxWidth, maxHeight, type = 'image/jpeg') { return new Promise((resolve, reject) => { const img = new Image(); img.src = dataUrl; @@ -1000,7 +1001,7 @@ export function createThumbnail(dataUrl, maxWidth, maxHeight) { ctx.drawImage(img, 0, 0, thumbnailWidth, thumbnailHeight); // Convert the canvas to a data URL and resolve the promise - const thumbnailDataUrl = canvas.toDataURL('image/jpeg'); + const thumbnailDataUrl = canvas.toDataURL(type); resolve(thumbnailDataUrl); };