当前位置: 首页>>代码示例>>Python>>正文


Python EXIF类代码示例

本文整理汇总了Python中EXIF的典型用法代码示例。如果您正苦于以下问题:Python EXIF类的具体用法?Python EXIF怎么用?Python EXIF使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了EXIF类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: EXIF

	def EXIF(self):
		try:
			return EXIF.process_file(open(self.image.path, 'rb'))
		except:
			 try:
				 return EXIF.process_file(open(self.image.path, 'rb'), details=False)
			 except:
				 return {}
开发者ID:news21,项目名称:news21-national,代码行数:8,代码来源:models.py

示例2: exif_to_human

def exif_to_human(image):
    fields = (
        ('Image Make', _('Camera manifacture')),
        ('Image Model', _('Camera model')),
        ('EXIF DateTimeDigitized', _('Digitized time')),
        ('EXIF DateTimeOriginal', _('Taken time')),
        ('Image Software', _('Image software')),
        ('EXIF ColorSpace', _('Color space')),
        ('EXIF FocalLength', _('Focal length')),
        ('EXIF FocalLengthIn35mmFilm', _('Forcal length(in 35mm)')),
        ('EXIF ISOSpeedRatings', _('ISO speed')),
        ('EXIF MaxApertureValue', _('Max aperture')),
        ('EXIF ExposureMode', _('Exposure mode')),
        ('EXIF ExposureProgram', _('Exposure program')),
        ('EXIF ExposureTime', _('Exposure time')),
        ('EXIF Flash', _('Flash')),
        ('EXIF LightSource', _('Light source')),
        ('EXIF DigitalZoomRatio', _('Digital zoom ratio')),
        ('EXIF ExifImageLength', _('Image length')),
        ('EXIF ExifImageWidth', _('Image width')),
        ('EXIF WhiteBalance', _('White balance')),
        ('EXIF Sharpness', _('Sharpness')),
        ('EXIF Contrast', _('Contrast')),
    )
    exif = []
    tags = EXIF.process_file(image, strict=True, stop_tag='JPEGThumbnail')
    for f in fields:
        if tags.has_key(f[0]):
            exif.append((f[1], str(tags[f[0]])))
    image.close()
    return exif
开发者ID:xueyw,项目名称:tsCloud,代码行数:31,代码来源:utils.py

示例3: post

    def post(self):
        # 画像データの取得
        image = self.request.get("image")
        # EXIFの解析
        sio = StringIO.StringIO(image)
        tags = EXIF.process_file(sio)
        
        # 画像の日付
        if tags.get('Image DateTime') != None:
            st = time.strptime(tags['Image DateTime'].values, '%Y:%m:%d %H:%M:%S')
            imgDateTime = datetime.datetime(*st[0:6])
        else:
            imgDateTime = None
        # 緯度
        if tags.get('GPS GPSLatitude') != None:
            lat = self.__getDegree(tags['GPS GPSLatitude'].values)
        else:
            lat = 0.0
        # 軽度
        if tags.get('GPS GPSLongitude') != None:
            lon = self.__getDegree(tags['GPS GPSLongitude'].values)
        else:
            lon = 0.0

        # データの保存
        pictData = PictureData(picture     = image,
                               geo         = "%f, %f" % (lat, lon),
                               imgdatetime = imgDateTime)
        PictureCtrls.set(pictData)

        self.redirect('/')
开发者ID:ngs,项目名称:hackathon-jp,代码行数:31,代码来源:post.py

示例4: buildDateFolders

def buildDateFolders(path = "", destination='', copy = True):
    files = fetchFiles(path)
    print("Processing files into dated folders for {0}".format(path))
    for eachFile in files:
        with open(eachFile.path, 'rb') as fh:
            tags = EXIF.process_file(fh, stop_tag="EXIF DateTimeOriginal")
            try:
                dateTaken = tags["EXIF DateTimeOriginal"].values
            except:
                dateTaken = None
        if dateTaken:
            try:
                destYearDir = "{0}\\{1}".format(destination, dateTaken.split(":")[0])
                destMonthDir = '{0}\\{1}'.format(destYearDir, dateTaken.split(":")[1])
                destMonthDay = '{0}\\{1}'.format(destMonthDir, dateTaken.split(":")[2].split(" ")[0])
                if not os.path.isdir(destYearDir):
                    os.mkdir(destYearDir)
                if not os.path.isdir(destMonthDir):
                    os.mkdir(destMonthDir)
                if not os.path.isdir(destMonthDay):
                    os.mkdir(destMonthDay)

                if copy:
                    if not os.path.isfile(os.path.join(eachFile.name, destMonthDay)):
                        print("Copying %s" % eachFile.name)
                        shutil.copy(eachFile.path, destMonthDay)
                else:
                    if not os.path.isfile(os.path.join(eachFile.name, destMonthDay)):
                        print("Moving %s from %s to %s" % (eachFile.name, eachFile.path, destMonthDay))
                        shutil.move(eachFile.path, destMonthDay)
            except:
                pass
    print('FINISHED MOVING FILES TO DATE FOLDERS')
开发者ID:jamesbdunlop,项目名称:jbd_playground,代码行数:33,代码来源:photoSorter.py

示例5: get_exif_data

def get_exif_data(filename):
    """Returns a dict of EXIF data for the given image file."""
    assert os.path.exists(filename), 'File not found: %s' % filename
    infile = open(filename, 'rb')
    exifdata = EXIF.process_file(infile)
    infile.close()
    return exifdata
开发者ID:mccutchen,项目名称:misc,代码行数:7,代码来源:jpgdatefixer.py

示例6: _load_fdl_one

    def _load_fdl_one(self, filename, file_data_list, movies):
        fn = fs_enc(filename)
        basename, extension = os.path.splitext(filename)
        with open(filename) as file:
            tags = EXIF.process_file(file, stop_tag="Image DateTime", details=False)
            if "Image DateTime" in tags:
                dt = datetime.datetime.strptime(str(tags["Image DateTime"]), "%Y:%m:%d %H:%M:%S")
            else:
                dt = modification_date(fn)

            # Set album time to the time of the oldest photo in the album
            if dt < self.album_datetime:
                self.album_datetime = dt

            print u"%s: %s" % (filename, dt)

            file_size = os.path.getsize(fn)
            if file_size < MAX_SIZE:
                checksum = md5_for_file(file)
            else:
                checksum = md5_for_string(fn + str(file_size))
            file_data = {"filename": filename, "datetime": dt, "checksum": checksum}
            file_data_list.append(file_data)

            # Maintain a set of all movies to filter out thumbnail
            # images below.
            if extension.lower() in (".mov", ".mpg", ".mpeg"):
                movies.add(basename)
开发者ID:tgulacsi,项目名称:picasa-directory-sync,代码行数:28,代码来源:sync.py

示例7: processEXIF

    def processEXIF(self):
        if hasattr(self, 'photoBody'):
            input = self.photoBody.getInputStream()
        else:
            input = file(self.file, 'r')

        data = input.read()
        input.close()
        stream = cStringIO.StringIO(data)
        try:
            exif = EXIF.process_file(stream)

            # First try DateTimeOriginal, falling back to DateTime
            takenString = str(exif.get('EXIF DateTimeOriginal',
                              exif['Image DateTime']))

            timestamp = time.mktime(time.strptime(takenString,
                                                  "%Y:%m:%d %H:%M:%S"))
            self.dateTaken = datetime.fromtimestamp(timestamp)
            if self.dateTaken.tzinfo is None:
                self.dateTaken = self.dateTaken.replace(tzinfo=self.itsView.tzinfo.default)

            self.exif = {}
            for (key, value) in exif.iteritems():
                if isinstance(value, EXIF.IFD_Tag):
                    self.exif[key] = unicode(value.printable)
                else:
                    self.exif[key] = unicode(value)

        except Exception, e:
            logger.debug("Couldn't process EXIF of Photo %s (%s)" % \
                (self.itsPath, e))
开发者ID:HackLinux,项目名称:chandler,代码行数:32,代码来源:Photos.py

示例8: _parse_and_add_exif

 def _parse_and_add_exif(self):
   import EXIF
   tags                    = EXIF.process_file(open(self.image.path,'rb'))
   self.make               = smart_unicode(tags.get('Image Make', '')).strip()
   self.model              = smart_unicode(tags.get('Image Model', '')).strip()
   self.date_raw           = smart_unicode(tags.get('EXIF DateTimeOriginal', '')).strip()
   self.width              = smart_unicode(tags.get('EXIF ExifImageWidth', '')).strip()
   self.height             = smart_unicode(tags.get('EXIF ExifImageHeight', '')).strip()
   self.orientation        = smart_unicode(tags.get('Image Orientation', '')).strip()
   self.resolution_unit    = smart_unicode(tags.get('Image ResolutionUnit', '')).strip()
   self.x_resolution       = smart_unicode(tags.get('Image XResolution', '')).strip()
   self.y_resolution       = smart_unicode(tags.get('Image YResolution', '')).strip()
   self.software           = smart_unicode(tags.get('Image Software', '')).strip()
   self.exposure_time      = smart_unicode(tags.get('EXIF ExposureTime', '')).strip()
   self.exposure_bias      = smart_unicode(tags.get('EXIF ExposureBiasValue', '')).strip() 
   self.exposure_program   = smart_unicode(tags.get('EXIF ExposureProgram', '')).strip() 
   self.flash              = smart_unicode(tags.get('EXIF Flash', '')).strip() 
   self.f_number           = smart_unicode(tags.get('EXIF FNumber', '')).strip() 
   self.aperture           = smart_unicode(tags.get('EXIF MaxApertureValue', '')).strip() 
   self.metering_mode      = smart_unicode(tags.get('EXIF MeteringMode', '')).strip() 
   self.focal_length       = smart_unicode(tags.get('EXIF FocalLength', '')).strip() 
   self.color_space        = smart_unicode(tags.get('EXIF ColorSpace', '')).strip()
   self.focal_length       = smart_unicode(tags.get('EXIF FocalLength', '')).strip()
   self.ycbcr_positioning  = smart_unicode(tags.get('Image YCbCrPositioning', '')).strip()
   self.sensing_method     = smart_unicode(tags.get('EXIF SensingMethod', '')).strip()
   
   if not self.date_created:
       if self.date_raw:
           self.date_created = self.date_raw
开发者ID:syncopated,项目名称:97bottles,代码行数:29,代码来源:models.py

示例9: rename_file

    def rename_file(self, filename, media_type):
        if media_type == "photo":
            with open(filename, "rb") as file_stream:
                try:
                    tags = EXIF.process_file(file_stream)
                    datestr = str(tags["EXIF DateTimeDigitized"])
                    date_object = datetime.datetime.strptime(datestr,
                                                             "%Y:%m:%d %H:%M:%S")
                    formatted_date = datetime.datetime.strftime(date_object,
                                                                "%Y-%m-%d_%I-%M-%S_%p")

                    self.year = str(datetime.datetime.strftime(date_object, "%Y"))
                    self.month = str(datetime.datetime.strftime(date_object, "%m"))
                    self.day = str(datetime.datetime.strftime(date_object, "%d"))

                    camera_model = str(tags["Image Model"]).replace(" ", "_")

                    image_filename = os.path.split(filename)[1]
                    if image_filename.startswith("DSC"):
                        image_filename_base = os.path.splitext(image_filename)[0]
                        self.new_name = (camera_model + "_" + image_filename_base[4:] + "_" +
                                         formatted_date + ".jpg")
                    else:
                        self.new_name = camera_model + "_" + formatted_date + ".jpg"
                except KeyError:
                    sys.stderr.write("Key error reading EXIF tags")
                    self.log.error("Key error reading EXIF tags")
                    pass
        else:
            video_filename  = self.get_video_date(filename)
            video_root, video_ext = os.path.splitext(filename)
            self.new_name = video_filename + video_ext.lower()

        return self.new_name
开发者ID:chadcooper,项目名称:vivian,代码行数:34,代码来源:vivian.py

示例10: exif_test

def exif_test(ifile):
    try:
        im = open(ifile, 'rb')
        tags = EXIF.process_file(im)
        tag_count = len(tags)
        return (True, tag_count) 
    except:
        return (False, None)
开发者ID:vincentdavis,项目名称:corrupt_image_finder,代码行数:8,代码来源:FindBadImages.py

示例11: exim_fetch

def exim_fetch(filename):
	f = open(filename, 'rb')
	tags = EXIF.process_file(f)
	test = [ item.split(':') for item in str(tags['EXIF DateTimeOriginal']).split(' ') ] 
	test = list(itertools.chain(*test))
	test = [ int(item) for item in test ]
	when = datetime(test[0], test[1], test[2], test[3], test[4], test[5])
	return when
开发者ID:vees,项目名称:narthex,代码行数:8,代码来源:lazypath.py

示例12: read_EXIF_data

 def read_EXIF_data(self):
     tags = EXIF.process_file_from_path(self.pathin)
     for key, attr in EXIF_map.iteritems():
         if tags.has_key(key):
             val = str(tags[key])
         else:
             val = ""
         setattr(self, attr, val)
开发者ID:ryanGT,项目名称:personal,代码行数:8,代码来源:photo_db_backup_before_switching_from_spreadsheet_to_numpy_arrays.py

示例13: exif_data

 def exif_data(self):
     if not hasattr(self, "_exif"):
         media_path = settings.GALLERY_SETTINGS.get('media_path')
         ex = self.get_exported()
         f = open(os.path.join(media_path, ex.normal_relpath.decode('string_escape')))
         self._exif = EXIF.process_file(f)
         f.close()
     return self._exif
开发者ID:ginking,项目名称:Gallery-1,代码行数:8,代码来源:models.py

示例14: __init__

    def __init__(self, file_path):
        """ EXIFReader 클래스 생성자 """

        self.file_path = file_path
        # Open image file for reading (binary mode)
        f = open(file_path, "rb")

        # Return Exif tags
        self.tags = EXIF.process_file(f)
开发者ID:keatonh,项目名称:photolog,代码行数:9,代码来源:exif_reader.py

示例15: getdate

	def getdate(self,filename):
		imagefile = file(filename,"rb")
		imagetags = EXIF.process_file(imagefile)
		imagefile.close()
#		print dir(imagetags['EXIF DateTimeOriginal'])
#		return imagetags['EXIF DateTimeOriginal']
		datestr = imagetags['EXIF DateTimeOriginal']
		datelist = re.search(r'(....):(..):(..) (..):(..):(..).*',datestr.printable).group
		date = datetime.datetime(int(datelist(1)),int(datelist(2)), int(datelist(3)), int(datelist(4)), int(datelist(5)), int(datelist(6)))
		return date
开发者ID:roman2838,项目名称:Fore,代码行数:10,代码来源:parse.py


注:本文中的EXIF类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。