[Python] python用来获得图片exif信息的库代码 →→→→→进入此内容的聊天室

来自 , 2019-10-25, 写在 Python, 查看 128 次.
URL http://www.code666.cn/view/f7dd39d4
  1. # library test/debug function (dump given files)
  2. if __name__ == '__main__':
  3.     import sys
  4.     import getopt
  5.  
  6.     # parse command line options/arguments
  7.     try:
  8.         opts, args = getopt.getopt(sys.argv[1:], "hqsdt:v", ["help", "quick", "strict", "debug", "stop-tag="])
  9.     except getopt.GetoptError:
  10.         usage(2)
  11.     if args == []:
  12.         usage(2)
  13.     detailed = True
  14.     stop_tag = 'UNDEF'
  15.     debug = False
  16.     strict = False
  17.     for o, a in opts:
  18.         if o in ("-h", "--help"):
  19.             usage(0)
  20.         if o in ("-q", "--quick"):
  21.             detailed = False
  22.         if o in ("-t", "--stop-tag"):
  23.             stop_tag = a
  24.         if o in ("-s", "--strict"):
  25.             strict = True
  26.         if o in ("-d", "--debug"):
  27.             debug = True
  28.  
  29.     # output info for each file
  30.     for filename in args:
  31.         try:
  32.             file=open(filename, 'rb')
  33.         except:
  34.             print "'%s' is unreadable\n"%filename
  35.             continue
  36.         print filename + ':'
  37.         # get the tags
  38.         data = process_file(file, stop_tag=stop_tag, details=detailed, strict=strict, debug=debug)
  39.         if not data:
  40.             print 'No EXIF information found'
  41.             continue
  42.  
  43.         x=data.keys()
  44.         x.sort()
  45.         for i in x:
  46.             if i in ('JPEGThumbnail', 'TIFFThumbnail'):
  47.                 continue
  48.             try:
  49.                 print '   %s (%s): %s' % \
  50.                       (i, FIELD_TYPES[data[i].field_type][2], data[i].printable)
  51.             except:
  52.                 print 'error', i, '"', data[i], '"'
  53.         if 'JPEGThumbnail' in data:
  54.             print 'File has JPEG thumbnail'
  55.         print
  56. #//python/8725

回复 "python用来获得图片exif信息的库代码"

这儿你可以回复上面这条便签

captcha