def get_image_dimensions(self, identify_program, path): image_details = ImageDetails() try: with Image.open(path) as image: image_details.set_mime_type(image.format) width, height = image.size image_details.set_width(width) image_details.set_height(height) except IOError: image_details.set_mime_type('NA') log.exception("File not found") return image_details
def get_image_dimensions(cls, identify_program, path): image_details = ImageDetails() try: # workaround to force the file to actually be closed by Pillow with open(path, 'rb') as img_file: with Image.open(img_file) as image: image_details.set_mime_type(image.format) width, height = image.size image_details.set_width(width) image_details.set_height(height) except IOError: image_details.set_mime_type('NA') log.exception("File not found") return image_details
def get_image_dimensions(cls, identify_program, path): # TODO: identify_program is not used image_details = ImageDetails() try: # workaround to force the file to actually be closed by Pillow with open(path, 'rb') as img_file: with Image.open(img_file) as image: image_details.set_mime_type(image.format) width, height = image.size image_details.set_width(width) image_details.set_height(height) except OSError: image_details.set_mime_type('NA') LOG.exception("Cannot identify image file") except Exception as ex: # TODO: Should we look into other possible exceptions? image_details.set_mime_type('NA') LOG.exception("Exception: {}".format(ex)) return image_details