Skip to content

Commit

Permalink
Revert failed merge "Improvements for Content Copy (go-gitea#21842)"
Browse files Browse the repository at this point in the history
This reverts commit f3b3149.
  • Loading branch information
fsologureng committed Nov 22, 2022
1 parent f3b3149 commit 40cdd3c
Showing 1 changed file with 0 additions and 48 deletions.
48 changes: 0 additions & 48 deletions web_src/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,51 +133,3 @@ export function convertImage(blob, mime) {
}
});
}

// convert a Blob to a DataURI
export function blobToDataURI(blob) {
return new Promise((resolve, reject) => {
try {
const reader = new FileReader();
reader.addEventListener('load', (e) => {
resolve(e.target.result);
});
reader.addEventListener('error', () => {
reject(new Error('FileReader failed'));
});
reader.readAsDataURL(blob);
} catch (err) {
reject(err);
}
});
}

// convert image Blob to another mime-type format.
export function convertImage(blob, mime) {
return new Promise(async (resolve, reject) => {
try {
const img = new Image();
const canvas = document.createElement('canvas');
img.addEventListener('load', () => {
try {
canvas.width = img.naturalWidth;
canvas.height = img.naturalHeight;
const context = canvas.getContext('2d');
context.drawImage(img, 0, 0);
canvas.toBlob((blob) => {
if (!(blob instanceof Blob)) return reject(new Error('imageBlobToPng failed'));
resolve(blob);
}, mime);
} catch (err) {
reject(err);
}
});
img.addEventListener('error', () => {
reject(new Error('imageBlobToPng failed'));
});
img.src = await blobToDataURI(blob);
} catch (err) {
reject(err);
}
});
}

0 comments on commit 40cdd3c

Please sign in to comment.