Python Bulk Modified Image EXIF properties
Altogether two documents
Config.ini//Put config file
exif.py//Main program Files
Config.ini File Source
[Global] Artist = www.blmm.com; the author datetimeoriginal = Now; the time is current time, as specified time is in the format: 2017:04:09 14:13:22) software = Adobe Photoshop CS6 Windows; program Name
exif.py File Source
#ecoding: Utf-8import pyexiv2 as Evimport timeimport osimport configparserclass Exif (): Def __init__ (self): confi g = Configparser.configparser () CONFIG.READFP (open (' Config.ini ', "RB")) self. Artist = Config.get ("Global", "Artist") self. Datetimeoriginal = Config.get ("Global", "datetimeoriginal") self. Software = Config.get ("Global", "Software") def Imgsave (self,dirname): for filename in Os.listdir (dirname): Path = dirname + filename if Os.path.isdir (path): path + = '/' Self.imgsave (path) else:self.imgExif (PATH) def imgexif (Self,path): Try:if self. Datetimeoriginal = = "Now": MyTime = Time.strftime ('%y:%m:%d%h:%m:%s ', Time.localtime (Time.time ())) Else:mytime = self. Datetimeoriginal exiv_image = ev. Imagemetadata (Path) exiv_image.read () exiv_image["Exif.Image.Artist"] = self.Artist exiv_image["Exif.Photo.DateTimeOriginal"] = mytime exiv_image["Exif.Image.Software"] = Self.s Oftware exiv_image.write () print U ' Picture: ', Path,u ' operation succeeded ' Except:print u ' Picture: ', Path,u ' Failed ' Def star (self): path = Raw_input (Unicode (' Enter picture path: ', ' utf-8 '). Encode (' GBK ') #newpath = Unicode (path , ' UTF8 ') self.imgsave (path+ '/') Self.star () print u ' #------------------------------------' Print U ' # program: Batch modification diagram Piece Exif info ' Print u ' # path format: g:\ picture ' Print U ' #------------------------------------' exif = EXIF () Exif.star ()
Operating effect:
Drag folder to window enter
Note: The Pyexiv2 module is used to modify EXIF information.
Https://launchpad.net/pyexiv2
Python Bulk Modified Image EXIF properties