def normalize_extension(extension):
    """
    Normalize extension
    Converts given extension to canonical format for storage
    :param extension: original extension
    :return: normalized extension
    """
    extension = extension.lower()

    exts = dict()
    exts['jpg'] = ['jpeg','jpe','jif','jfif','jfi''jp2','j2k','jpx','jpf','jpm']
    exts['tif'] = ['tiff']
    exts['tar.gz'] = ['tgz']

    for canonical, variants in exts.items():
        if extension in variants:
            extension = canonical
            break

    return extension