import base64


def b64str_to_img_file(src, saveto, urlsafe=False):
    """
    Re-generate image file from any Base64 string generated by img_to_base64_str(), and save it to disk.
    :param src: The string you want to decode.
    :param saveto: Specify the path of generated file to save to.
    :param urlsafe: Trigger using URL-Safe format. It must be consistent with your choice when first generating this string.
    :return: An integer of the size of the picture
    """
    file_base64 = src.encode('utf-8')

    if urlsafe:
        file_byte = base64.urlsafe_b64decode(file_base64)
    else:
        file_byte = base64.standard_b64encode(file_base64)

    OUT_FILE = open(saveto, 'wb')
    return OUT_FILE.write(file_byte)