def readExifForImages(images): data = [] for image_path in images: print image_path with open(image_path, 'rb') as image: tags = exifread.process_file(image, details=False) # title, filename, dropbox_url, location, camera, focal_length, aperture, shutter_speed, iso, date, width, height, category = entry[:13] # title - prompt title = prompt('Title: ') # filename - parse file_parts = image_path.split('/') filename = os.path.join(file_parts[-2], file_parts[-1]) # dropbox_url - prompt dropbox_url = prompt('Dropbox URL: ')[24:-5] # location - prompt location = prompt('Location or ("' + DEFAULT_LOCATION + '"): ', DEFAULT_LOCATION) # camera camera = str(tags['Image Model']).title() # focal_length focal_length = str(tags['EXIF FocalLength']) + 'mm' # aperture aperture = 'f/' + str(fractionToFloat(str(tags['EXIF FNumber']))) # shutter_speed shutter_speed = str(tags['EXIF ExposureTime']) + 's' # iso iso = int(str(tags['EXIF ISOSpeedRatings'])) # date date = str( datetime.strptime(str(tags['Image DateTime']), '%Y:%m:%d %H:%M:%S').date()) # width + height width, height, _, _ = dimensions.dimensions(image_path) # category f/t category = 'food' if prompt( 'Category (f/t): ') == 'f' else 'travel' value = (title, filename, dropbox_url, location, camera, focal_length, aperture, shutter_speed, iso, date, width, height, category) data.append(value) return data
def imageSize(project, imagePath): for resourcePath in project['resourcePaths']: path = os.path.join(project['location'], resourcePath['path']) finalPath = os.path.join(path, imagePath) if os.path.isfile(finalPath): return list(dimensions.dimensions(finalPath))[:2] basename = os.path.basename(imagePath) dirname = os.path.dirname(imagePath) finalPath = os.path.join(path, dirname, 'resources-auto', basename) if os.path.isfile(finalPath): d = dimensions.dimensions(finalPath) return [int(d[0] * 0.25), int(d[1] * 0.25)] finalPath = os.path.join(path, basename, 'resources-iphone', basename) if os.path.isfile(finalPath): return list(dimensions.dimensions(finalPath))[:2] logging.warning('Failed to determine size of image \'%s\'' % imagePath) return [0, 0]
def check_app_icon_2x_dimensions(app, reporter): """Check that static/appIcon_2x is 72x72px or less""" relative_file_path = ["static", "appIcon_2x.png"] if app.file_exists(*relative_file_path): file_path = os.path.join(*relative_file_path) width, height, type, path = dimensions.dimensions( app.get_filename(*relative_file_path)) if width > 72 or height > 72: reporter_output = ( "static/appIcon_2x.png should be 72x72 or less, but was" " detected as {}x{}. File: {}").format(width, height, file_path) reporter.fail(reporter_output, file_path) else: reporter.fail("static/appIcon_2x.png does not exist.")
def check_app_logo_2x_dimensions(app, reporter): """Check that static/appLogo_2x.png is 320x80px or less""" relative_file_path = ["static", "appLogo_2x.png"] if app.file_exists(*relative_file_path): file_path = os.path.join(*relative_file_path) width, height, type, path = dimensions.dimensions( app.get_filename(*relative_file_path)) if (width > 320 or height > 80): reporter_output = ( "static/appLogo_2x.png should be 320x80 or less, but was" " detected as {}x{}. File: {}").format(width, height, file_path) reporter.fail(reporter_output, file_path) else: reporter.not_applicable("static/appLogo_2x.png does not exist.")
def isValid(logoPath): if Logo.doesNotExist(logoPath): raise LogoException('Logo does not exist.', logoPath) try: # Try to parse image dimensions width, height = dimensions(logoPath)[:2] except NotImplementedError: raise LogoException("Could not parse logo format.") if Logo.isTooWide(width): LogoRescaler.rescale(path=logoPath, width=500) elif Logo.isTooHigh(height): LogoRescaler.rescale(path=logoPath, height=500) return True
def render_news(self, trump): temp_file = urllib.urlretrieve(trump["urlToImage"]) dims = dimensions.dimensions(temp_file[0]) response = { "style": "media", "id": str(uuid.uuid4()), "url": trump["url"], "title": trump["title"], "description": { "value": trump["description"], "format": "text" }, "thumbnail": { "url": trump["urlToImage"], "url@2x": trump["urlToImage"], "width": dims[0], "height": dims[1] } } return response
def __get_image_tag(self, image): """ Get a path to a image file and return the tags to sort this image :param image: (str or unipath.Path) path to an image file :return: (tuple) with the tags to sort the image """ # load sorting methods criteria = [self.sort] if self.sub_sorts: criteria.extend(self.sub_sorts) full_tags = list() # find all tags for criterion in criteria: # method for size if criterion == 'size': image_properties = dimensions(str(image)) tag = '{}x{}'.format(image_properties[0], image_properties[1]) full_tags.append(self.__image_tag(tag)) # method for date if criterion == 'date': # set possible date exif keys keys = ['Image DateTime', 'EXIF DateTimeDigitized', 'GPS GPSDate'] # fetch the key values with open(image, 'r') as file_handler: exif = process_file(file_handler) for key in keys: tag = exif.get(key, False) if tag: break if not tag: file_path = Path(image) tag = strftime('%Y:%m:%d', localtime(file_path.ctime())) # create sub tags tag = str(tag) if tag != 'Undefined Date': if len(tag.strip()) > 10: date_tag = datetime.strptime(tag, '%Y:%m:%d %H:%M:%S') else: date_tag = datetime.strptime(tag, '%Y:%m:%d') for sub_tag in ['%Y', '%m', '%d']: formatted = date_tag.strftime(sub_tag) full_tags.append(self.__image_tag(formatted, True)) else: full_tags.append(self.__image_tag(tag)) # method for origin if criterion == 'origin': # fetch the key values with open(image, 'r') as file_handler: # get info exif = process_file(file_handler) model = exif.get('Image Model', False) software = exif.get('Image Software', False) make = exif.get('Image Make', False) # if software is just a version number, skip it regex = compile('[^a-zA-Z]+') test = str(software) if len(regex.sub('', test.replace('Camera', ''))) == 0: software = False # generate tag if model and software: tag = '{} - {}'.format(model, software) elif model: tag = str(model) elif software: tag = str(software) elif make: tag = str(make) else: tag = 'Undefined Origin' # append tag full_tags.append(self.__image_tag(tag)) return tuple(full_tags)
def image_info(data: bytes): with temp_input(data) as image: return dimensions(image)[:3]
def __init__(self, image_path): """This only supports PNG/JPEG/GIF image formats, and will thrown NotImplementedError for non supported formats """ FileResource.__init__(self, image_path) self.image_path = image_path self.meta = dimensions.dimensions([self.image_path])[0] # workaround for https://github.com/philadams/dimensions/issues/4