Compress too large images for Google captions

This commit is contained in:
Cohee
2023-12-14 22:28:22 +02:00
parent cde9903fcb
commit 6406f76c7d
2 changed files with 12 additions and 3 deletions

View File

@ -1030,6 +1030,11 @@ export function loadFileToDocument(url, type) {
* @returns {Promise<string>} A promise that resolves to the thumbnail data URL.
*/
export function createThumbnail(dataUrl, maxWidth, maxHeight, type = 'image/jpeg') {
// Someone might pass in a base64 encoded string without the data URL prefix
if (!dataUrl.includes('data:')) {
dataUrl = `data:image/jpeg;base64,${dataUrl}`;
}
return new Promise((resolve, reject) => {
const img = new Image();
img.src = dataUrl;