/** * Manipulation des images */ class ImageUtils { /** * Returns a blob with the given data and the image filetype * * @param data * @param filetype */ public static newBlob(data: string, filetype: string = 'image/jpeg'): Blob { return new Blob([data as BlobPart], {type: filetype}); } /** * Transforme un Blob en Base64 * @param {Blob} blob */ public static async blobToBase64(blob: Blob): Promise { // /!\ Attention: lors de tests unitaires, 'blob.text' plantera si utilisée en même temps que vi.useFakeTimers() const content = Buffer.from(await blob.text()).toString('base64'); return `data:${blob.type};base64,${content}` } } export default ImageUtils