Ejemplo n.º 1
0
def verify_image(info_file, valid, invalid,
        method_register=VERIFY_WITHOUT_PIL):
    extension = system.file_extension(info_file['path'])
    if extension in method_register.extensions:
        verify_image_without_pil(info_file, method_register, valid, invalid)
    else:
        verify_image_with_pil(info_file, valid, invalid)
Ejemplo n.º 2
0
def open_image_without_pil(filename, method_register):
    """Try to open images which PIL can't handle."""
    extension = system.file_extension(filename)
    if extension in method_register.extensions:
        methods = method_register.get_methods(extension)
        for open_method in methods:
            image = open_method(filename)
            if image:
                return image
Ejemplo n.º 3
0
def verify_image_without_pil(info_file, method_register, valid, invalid):
    """Try to verify images which PIL can't handle."""
    extension = system.file_extension(info_file['path'])
    methods = method_register.get_methods(extension)
    for verify_method in methods:
        if verify_method(info_file['path']):
            valid.append(info_file)
            return True
    invalid.append(info_file['path'])
    return False
Ejemplo n.º 4
0
def get_format_filename(filename):
    """Guess the image format by the filename.

    :param filename: filename
    :type filename: string
    :returns: image format
    :rtype: string

    .. warning::

        This is only meant to check before saving files. For existing files
        open the image with PIL and check its format attribute.

    >>> get_format_filename('test.tif')
    'TIFF'
    """
    return get_format(system.file_extension(filename))
Ejemplo n.º 5
0
def get_format_filename(filename):
    """Guess the image format by the filename.

    :param filename: filename
    :type filename: string
    :returns: image format
    :rtype: string

    .. warning::

        This is only meant to check before saving files. For existing files
        open the image with PIL and check its format attribute.

    >>> get_format_filename('test.tif')
    'TIFF'
    """
    return get_format(system.file_extension(filename))