matheusdavidson / angular-cropperjs

CropperJS integration for Angular +6
MIT License
109 stars 69 forks source link

cropper js not working for edge browser ,canvas.toBlob() is not function #60

Open omairaslam817 opened 4 years ago

omairaslam817 commented 4 years ago

why canvas.toBlob() is unfriend for edge browser ,kindly share a possible solution for edge browser

liesahead commented 3 years ago

Use toDataUrl() instead and then

/**
 * Converts base 64 to File object
 *
 * @param base64String Image in base 64 string format
 * @param name filename
 */
export const dataURLtoFile = (base64String: string, name: string, type: string): File => {
    const parts = base64String.split(',');
    const byteString = atob(parts[1]);
    const intArray = new Uint8Array(byteString.length);

    // Set the bytes of the buffer to the correct values
    for (let i = 0; i < byteString.length; i++) {
        intArray[i] = byteString.charCodeAt(i);
    }

    // IE does not support File() constructor, so we need to create blob.
    // But blob differs from file only because it does not have lastModified and name, which can be added manually
    const file = new Blob([intArray], { type });
    file['name'] = name;
    file['lastModified'] = Date.now();

    return file as File;
};