imageUtils.ts 796 B

12345678910111213141516171819202122232425262728293031
  1. import SysUtils from "~/services/utils/SysUtils";
  2. /**
  3. * Manipulation des images
  4. */
  5. class ImageUtils {
  6. /**
  7. * Returns a blob with the given data and the image filetype
  8. *
  9. * @param data
  10. * @param filetype
  11. */
  12. public static newBlob(data: string, filetype: string = 'image/jpeg'): Blob {
  13. return new Blob([data as BlobPart], {type: filetype});
  14. }
  15. /**
  16. * Transforme un Blob en Base64
  17. * @param {Blob} blob
  18. */
  19. public static async blobToBase64(blob: Blob): Promise<string> {
  20. return new Promise((resolve, _) => {
  21. const reader = new FileReader();
  22. // @ts-ignore
  23. reader.onloadend = () => resolve(reader.result);
  24. reader.readAsDataURL(blob);
  25. });
  26. }
  27. }
  28. export default ImageUtils