예제 #1
0
파일: images.py 프로젝트: cdrappi/goose3
 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
예제 #2
0
파일: images.py 프로젝트: rebekz/goose3
 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
예제 #3
0
 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 IOError:
         image_details.set_mime_type('NA')
         LOG.exception("File not found")
     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