

def convert_image(target, image_size):
    (_, extension) = os.path.splitext(os.path.basename(target))
    if (image_size and (not all(image_size))):
        return target
    invalid_extensions = ('.bmp', '.dib', '.tiff', '.tif')
    try:
        image = Image.open(target)
    except IOError:
        return target
    image_format = image.format
    image_file_name = target
    if ((image_size is not None) and (image.size != image_size)):
        try:
            image = image.resize(image_size, Image.ANTIALIAS)
        except IOError:
            pass
    if (extension.lower() in invalid_extensions):
        image_format = 'GIF'
        image_file_name = replace_ext(target, '.gif')
    try:
        image.save(image_file_name, image_format)
    except IOError:
        return target
    return image_file_name

dataset/ETHPy150Open PolicyStat/docx2html/docx2html/core.py convert_image/original