diff --git a/README.md b/README.md index 1edcf47..52a3fe0 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ Go to "Manage my extensions" on your browser, then click on "Load unpa
![Mouseover2](./assets/mouseover2.gif) - Infinite try: click as much as you want on the question (don't forget to reset the question). - Save history: allows you to create a conversation with ChatGPT by saving the previous question with its answer. However, note that it can consume a significant number of tokens. -- Include images (only work with gpt-4): allows you to include the images from the question to be send to the chatgpt api. However, note that it can consume a significant number of tokens. +- Include images (only work with gpt-4): allows you to include the images from the question to be send to the chatgpt api. The quality is reduced to 75% to use less tokens.However, note that it can consume a significant number of tokens.
![Images](./assets/images.gif) ## Internal Features diff --git a/src/utils/image-to-base64.ts b/src/utils/image-to-base64.ts index f642c34..4232f53 100644 --- a/src/utils/image-to-base64.ts +++ b/src/utils/image-to-base64.ts @@ -1,9 +1,10 @@ /** * Convert an image html element into a base64 image string * @param imageElement + * @param quality (default: 0.75 -> 75%) * @returns */ -function imageToBase64(imageElement: HTMLImageElement): Promise { +function imageToBase64(imageElement: HTMLImageElement, quality = 0.75): Promise { return new Promise(resolve => { const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); @@ -21,7 +22,7 @@ function imageToBase64(imageElement: HTMLImageElement): Promise { canvas.height = img.height; ctx.drawImage(img, 0, 0); - const base64 = canvas.toDataURL('image/png'); + const base64 = canvas.toDataURL('image/png', quality); resolve(base64); canvas.remove();