def get_exif(fn): i = Image.open(fn) info = i._getexif() ret = {} for tag, value in info.items(): decoded = TAGS.get(tag, tag) ret[decoded] = value return ret
def get_exif(fn): ret = {} i = image.open(fn) info = i._getexif() for tag, value in info.items(): decoded = tags.get(tag, tag) ret[decoded] = value return ret
def get_metadata(im): ret = {} if not hasattr(im, 'getim'): # a PIL Image object raise NotIsPilObject info = im._getexif() for tag, value in info.items(): decoded = TAGS.get(tag, tag) ret[decoded] = value return ret
def get_exif(fn): """Routine recuperee sur le net""" ret = {} i = Image.open(fn) info = i._getexif() for tag, value in info.items(): decoded = TAGS.get(tag, tag) ret[decoded] = value return ret
def get_exif(dir_path,fileDelimiter): """Gets the exif data of a file and calls rename function""" ret = {} choice = "" only_images = [] only_path = fileDelimiter all_files = file_recursive.get_file_list_recursively(dir_path) for f in all_files: if not os.path.isdir(f) and imghdr.what(f): only_images.append(f) #print only_images for fn in only_images: #print fn full_path_list = fn.split(fileDelimiter) only_path=fileDelimiter for i in range(len(full_path_list)-2): only_path += full_path_list[i+1]+fileDelimiter #print 'only_path=%s' % only_path file_name = full_path_list[len(full_path_list)-1]# filename might be needed later file_extension = file_name.partition('.')[2] #print 'file_name=%s' % file_name #print 'file_extension=%s' % file_extension i = Image.open(fn) print 'Processing %s' % (fn) info = i._getexif() if not info: print ' Done processing %s' % (fn) continue for tag, value in info.items(): if (TAGS.get(tag, tag)==EXIF_FOR_DATE_AND_TIME): #print value #temp = value.replace(':','_') #print 'temp=' #print temp #temp=temp.partition(' ') #print 'temp2 = ' #print temp #print only_path+(prefix+"_"+temp[0]+"__"+temp[2]+"."+file_extension) #pdb.set_trace() """if os.path.exists(only_path+(temp[0]+"__"+temp[2]+"."+file_extension)) or os.path.exists(only_path+(prefix+"_"+temp[0]+"__"+temp[2]+"."+file_extension)): print '%s has same information as %s' % (fn,only_path+(temp[0]+"__"+temp[2]+"."+file_extension)) print ' What do you want to do? (R) Replace,(K) Keep both,(D) Do not do anything' choice = raw_input("Enter---> ") print choice continue""" """if (prefix): #print 'fn=%s' % fn os.rename(fn,only_path+(prefix+"_"+temp[0]+"__"+temp[2]+"."+file_extension)) else: #'fn2=%s' % fn os.rename(fn,only_path+(temp[0]+"__"+temp[2]+"."+file_extension)) """ rename_with_format(fn,only_path,value,file_extension) print ' Done processing %s' % (fn)
def exif(img): exif_data = {} try: i = Image.open(img) tags = i._getexif() for tag, value in tags.items(): decoded = TAGS.get(tag, tag) exif_data[decoded] = value except: pass return exif_data
def get_exif_data(fname): """Get embedded EXIF data from image file.""" ret = {} img = Image.open(fname) if hasattr(img, '_getexif' ): exifinfo = img._getexif() if exifinfo != None: for tag, value in exifinfo.items(): decoded = TAGS.get(tag, tag) ret[decoded] = value return ret
def open_picture(filename, return_tags=True): img = Image.open(filename) if return_tags: #from ExifTags import TAGS info = img._getexif() tags = {} for tag, value in info.items(): decoded = TAGS.get(tag, tag) tags[decoded] = value else: tags = None return img, tags
def __get_exif(self,i): ret = {} try: info = i._getexif() if info is not None: for tag,value in info.items(): decoded = TAGS.get(tag,tag) ret[decoded] = value except: ret = {} return ret
def image_rotate_exif(album, filename): orientation_steps = { 3: 2, 6: 1, 8: 3 } if not is_edited(album, filename): img = Image.open(os.path.join(current_app.config['ALBUMS_DIR'], album, filename)) exif = img._getexif() ret = {} for tag, value in exif.items(): decoded = TAGS.get(tag, tag) ret[decoded] = value if ret.has_key('Orientation'): orientation = int(ret['Orientation']) if orientation_steps.has_key(orientation): _image_rotate(album, filename, orientation_steps[orientation])
def get_date(fn): global last_value im = Image.open(fn) if hasattr(im, '_getexif'): exifdata = im._getexif() for tag, value in exifdata.items(): decoded = TAGS.get(tag, tag) if decoded == "DateTime": last_value = value return value print decoded, value return last_value raise Exception("not DateTime")
def get_exif_data(fname,key): """Get embedded EXIF data from image file.""" ret = {} try: img = Image.open(fname) if hasattr( img, '_getexif' ): exifinfo = img._getexif() if exifinfo != None: for tag, value in exifinfo.items(): decoded = TAGS.get(tag,tag) if key==decoded: ret[decoded] = value except IOError: print 'IOERROR ' + fname return ret.get(key).replace(" ","-")
def get_exif(imageFile): logger.debug("extracting exif for file: " + imageFile) ret = {} i = Image.open(imageFile) try: info = i._getexif() if (info == None): logger.debug("No exif information found for file: " + imageFile) return for tag, value in info.items(): decoded = TAGS.get(tag, tag) ret[decoded] = value return ret except AttributeError: logger.debug("No exif information found for file: " + imageFile) return
def ThumbnailCreate(albumdir, thumbdir, size): if not isinstance(albumdir,type("")): albumdir="" for filename in glob.glob(albumdir+"*.jpg"): exif = filename._getexif() if exif != None: for tag, value in exif.items(): decoded = TAGS.get(tag, tag) if decoded == 'Orientation': if value == 3: filename = filename.rotate(180) if value == 6: filename = filename.rotate(270) if value == 8: filename = filename.rotate(90) break im = Image.open(filename) im.thumbnail(size, Image.ANTIALIAS) im.save(thumbdir + thumb_prefix + filename, "JPEG")
def getExif(image): """ get exif meta data from image """ metas = {} try: img = Image.open(image) except IOError: print "*WARN* invalid photo type " + str(image) return None info = img._getexif() if info is None: print "*WARN* no EXIF information of " + str(image) return None for tag, value in info.items(): decoded = TAGS.get(tag, tag) metas[decoded] = value return metas
def adjust_image_orientation(cls, image): """Since the iPhone will store an image on its side but with EXIF data stating that it should be rotated, we need to find that EXIF data and correctly rotate the image before storage.""" if hasattr(image, '_getexif'): exif = image._getexif() if exif: for tag, value in exif.items(): decoded = TAGS.get(tag, tag) if decoded == 'Orientation': if value == 6: image = image.rotate(-90) if value == 8: image = image.rotate(90) if value == 3: image = image.rotate(180) break return image
def getExifCreationDate(filename, offsets): """ Get the EXIF creation date for a file. If the file is not an image, then we'll just return None. @param filename: Absolute path to a file @param offsets: Configured offsets as from parseOffsets() @return: EXIF creation date, or None if there is no such information. """ dateTime = None cameraModel = None try: i = Image.open(filename) info = i._getexif() keymap = {} if info is not None: for tag, value in info.items(): decoded = TAGS.get(tag, tag) keymap[decoded] = value # Some cameras have DateTimeOrignal, and some only have DateTime. On # the ones that have DateTimeOriginal, it looks like DateTime might be # different (newer), possibly because the file was modified on the # camera or something. We definitely want to use DateTimeOriginal if # we have it. if keymap.has_key("DateTimeOriginal"): dateTime = keymap["DateTimeOriginal"] elif keymap.has_key("DateTime"): dateTime = keymap["DateTime"] if keymap.has_key("Model"): cameraModel = keymap["Model"] except IOError: pass if dateTime is None: sys.stderr.write("Warning, file has no date/time: %s\n" % filename) return None else: exifCreationTime = datetime.strptime(dateTime, "%Y:%m:%d %H:%M:%S") if cameraModel in offsets: exifCreationTime += offsets[cameraModel] return exifCreationTime
def update_exif(album, filename): exifdir = os.path.join(current_app.config['CACHE_DIR'], album, 'exif') exiffile = os.path.join(exifdir, os.path.basename(filename) + '.exif') if not os.path.exists(exifdir): os.mkdir(exifdir) img = Image.open(os.path.join(current_app.config['ALBUMS_DIR'], album, filename)) exif = img._getexif() if exif == None: return ret = {} if exif: for tag, value in exif.items(): decoded = TAGS.get(tag, tag) ret[decoded] = value f = open(exiffile, 'w') for key in supported_exiftags: if ret.has_key(key): f.write("%s|%s\n" % (key, ret[key])) f.close() return ret
def import_image(path, source_folder, thumb_path = settings.THUMBNAIL_DIR): # Check if it already exists try: ph = Photo.objects.get(path = path) return ph except Photo.DoesNotExist: # The photo is new, continue with importing pass # Collect various data about the image im = Image.open(path) (width, height) = im.size exif_raw = im._getexif() exif_parsed = {} for tag, value in exif_raw.items(): decoded = TAGS.get(tag, tag) exif_parsed[decoded] = value (exposure_numerator, exposure_denominator) = exif_parsed['ExposureTime'] # It is assumed that django will change this # into the time zone set in settings. taken_date = datetime.fromtimestamp(mktime( strptime( exif_parsed['DateTimeOriginal'], "%Y:%m:%d %H:%M:%S" ) )) file_size = os.stat(path).st_size manufacturer_name = exif_parsed['Make'] camera_name = exif_parsed['Model'] manufacturer, created = Manufacturer.objects.get_or_create( name = manufacturer_name ) camera, created = Camera.objects.get_or_create( manufacturer = manufacturer, name = camera_name ) focal_length = exif_parsed['FocalLength'][0] aperture = exif_parsed['FNumber'][0] iso = exif_parsed['ISOSpeedRatings'] # Compute file name for large size largefile = os.path.join(thumb_path, large_sub_path(path)) # Save large view size save_resized(im, largefile, (1000, 1000)) # Compute file name for medium size mediumfile = os.path.join(thumb_path, medium_sub_path(path)) # Save medium view size save_resized(im, mediumfile, (600, 600)) # Compute file name for thumbnail thumbfile = os.path.join(thumb_path, thumb_sub_path(path)) # Save thumbnail save_resized(im, thumbfile) # Save to database ph = Photo( path = path, source_folder = source_folder, width = width, height = height, exposure_numerator = exposure_numerator, exposure_denominator = exposure_denominator, iso = iso, taken_date = taken_date, file_size = file_size, camera = camera, focal_length = focal_length, aperture = aperture ) ph.save() return ph