How to use the pyexiv2.Image function in pyexiv2

To help you get started, we’ve selected a few pyexiv2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gramps-project / gramps / src / plugins / gramplet / MetadataViewer.py View on Github external
def display_exif_tags(self, media):
        """
        Display the exif tags.
        """
        full_path = Utils.media_path_full(self.dbstate.db, media.get_path())
        
        if LesserVersion: # prior to v0.2.0
            try:
                metadata = pyexiv2.Image(full_path)
            except IOError:
                self.set_has_data(False)
                return
            metadata.readMetadata()
            for key in metadata.exifKeys():
                label = metadata.tagDetails(key)[0]
                if key in ("Exif.Image.DateTime",
                           "Exif.Photo.DateTimeOriginal",
                           "Exif.Photo.DateTimeDigitized"):
                    human_value = format_datetime(metadata[key])
                else:
                    human_value = metadata.interpretedExifValue(key)
                self.model.add((label, human_value))

        else: # v0.2.0 and above
            metadata = pyexiv2.ImageMetadata(full_path)
github gramps-project / gramps / src / plugins / gramplet / MetadataViewer.py View on Github external
def get_has_data(self, media):
        """
        Return True if the gramplet has data, else return False.
        """
        if media is None:
            return False

        full_path = Utils.media_path_full(self.dbstate.db, media.get_path())
        
        if LesserVersion: # prior to v0.2.0
            try:
                metadata = pyexiv2.Image(full_path)
            except IOError:
                return False
            metadata.readMetadata()
            if metadata.exifKeys():
                return True

        else: # v0.2.0 and above
            metadata = pyexiv2.ImageMetadata(full_path)
            try:
                metadata.read()
            except IOError:
                return False
            if metadata.exif_keys:
                return True

        return False
github gramps-project / gramps / gramps / plugins / gramplet / editexifmetadata.py View on Github external
im.save(dest_file) 

        # pyexiv2 source image file
        if OLD_API:  # prior to pyexiv2-0.2.0
            src_meta = pyexiv2.Image(full_path)
            src_meta.readMetadata()
        else:
            src_meta = pyexiv2.ImageMetadata(full_path)
            src_meta.read()

        # check to see if source image file has any Exif metadata?
        if _get_exif_keypairs(src_meta):

            if OLD_API:  # prior to pyexiv2-0.2.0
                # Identify the destination image file
                dest_meta = pyexiv2.Image(dest_file)
                dest_meta.readMetadata()

                # copy source metadata to destination file 
                src_meta.copy(dest_meta, comment =False)

                # writes all Exif Metadata to image even if the fields are all empty so as to remove the value
                self.write_metadata(dest_meta)
            else:  # pyexiv2-0.2.0 and above
                # Identify the destination image file
                dest_meta = pyexiv2.ImageMetadata(dest_file)
                dest_meta.read()

                # copy source metadata to destination file 
                src_meta.copy(dest_meta, comment =False)

                # writes all Exif Metadata to image even if the fields are all empty so as to remove the value
github gramps-project / gramps / src / plugins / lib / libmetadata.py View on Github external
def get_has_data(self, full_path):
        """
        Return True if the gramplet has data, else return False.
        """
        # pylint: disable=E1101
        if OLD_API: # prior to v0.2.0
            try:
                metadata = pyexiv2.Image(full_path)
            except IOError:
                return False
            metadata.readMetadata()
            for tag in TAGS:
                if tag[1] in metadata.exifKeys():
                    return True

        else: # v0.2.0 and above
            metadata = pyexiv2.ImageMetadata(full_path)
            try:
                metadata.read()
            except IOError:
                return False
            for tag in TAGS:
                if tag[1] in metadata.exif_keys:
                    return True
github gramps-project / addons-source / EditExifMetadata / editexifmetadata.py View on Github external
def setup_image(self, full_path):
        """
        This will:
            * create the plugin image instance if needed,
            * setup the tooltips for the data fields,
            * setup the tooltips for the buttons,
        """
        if OLD_API:  # prior to pyexiv2-0.2.0
            metadata = pyexiv2.Image(full_path)
            try:
                metadata.readMetadata()
            except (IOError, OSError):
                self.set_has_data(False)
                metadata = False

        else:  # pyexiv2-0.2.0 and above
            metadata = pyexiv2.ImageMetadata(full_path)
            try:
                metadata.read()
            except (IOError, OSError):
                self.set_has_data(False)
                metadata = False

        return metadata
github gramps-project / gramps / gramps / plugins / gramplet / editexifmetadata.py View on Github external
ext_type = self.exif_widgets["ImageTypes"].get_active()
        if ext_type == 0:
            return False

        basename += self._VCONVERTMAP[ext_type]

        # new file name and dirpath
        dest_file = os.path.join(filepath, basename)

        # open source image file
        im = Image.open(full_path)
        im.save(dest_file) 

        # pyexiv2 source image file
        if OLD_API:  # prior to pyexiv2-0.2.0
            src_meta = pyexiv2.Image(full_path)
            src_meta.readMetadata()
        else:
            src_meta = pyexiv2.ImageMetadata(full_path)
            src_meta.read()

        # check to see if source image file has any Exif metadata?
        if _get_exif_keypairs(src_meta):

            if OLD_API:  # prior to pyexiv2-0.2.0
                # Identify the destination image file
                dest_meta = pyexiv2.Image(dest_file)
                dest_meta.readMetadata()

                # copy source metadata to destination file 
                src_meta.copy(dest_meta, comment =False)
github gramps-project / addons-source / contrib / ImageMetadataGramplet / ImageMetadataGramplet.py View on Github external
def setup_image(self, full_path, createimage =False):
        """
        will return an image instance and read the Exif metadata.

        if createimage is True, it will create the pyexiv2 image instance...

        LesserVersion -- prior to pyexiv2-0.2.0
                      -- pyexiv2-0.2.0 and above...
        """

        if createimage:
            if LesserVersion:
                self.plugin_image = pyexiv2.Image(full_path)
            else:
                self.plugin_image = pyexiv2.ImageMetadata(full_path)

        if LesserVersion:
            self.plugin_image.readMetadata()

            # get all KeyTags for this image for diplay only...
            self.MediaDataTags = [KeyTag for KeyTag in chain(
                                self.plugin_image.exifKeys(),
                                self.plugin_image.xmpKeys(),
                                self.plugin_image.iptcKeys() ) ]
        else:
            self.plugin_image.read()

            # get all KeyTags for this image for diplay only...
            self.MediaDataTags = [KeyTag for KeyTag in chain(
github gramps-project / addons-source / EditExifMetadata / editexifmetadata.py View on Github external
ext_type = self.exif_widgets["ImageTypes"].get_active()
        if ext_type == 0:
            return False

        basename += self._VCONVERTMAP[ext_type]

        # new file name and dirpath
        dest_file = os.path.join(filepath, basename)

        # open source image file
        im = Image.open(full_path)
        im.save(dest_file)

        # pyexiv2 source image file
        if OLD_API:  # prior to pyexiv2-0.2.0
            src_meta = pyexiv2.Image(full_path)
            src_meta.readMetadata()
        else:
            src_meta = pyexiv2.ImageMetadata(full_path)
            src_meta.read()

        # check to see if source image file has any Exif metadata?
        if _get_exif_keypairs(src_meta):

            if OLD_API:  # prior to pyexiv2-0.2.0
                # Identify the destination image file
                dest_meta = pyexiv2.Image(dest_file)
                dest_meta.readMetadata()

                # copy source metadata to destination file
                src_meta.copy(dest_meta, comment =False)
github gramps-project / addons-source / contrib / ImageMetadataGramplet / ImageMetadataGramplet.py View on Github external
def display_exif_tags(self, full_path, metadataTags):
        """
        reads the image metadata after the pyexiv2.Image has been created

        @param: full_path -- complete path to media object on local computer
        @param: metadataTags -- a list of the exif KeyTags that we will be displayed...
        """
        MediaDataTags = []
        self.model.clear()

        if LesserVersion:  # prior to pyexiv2-0.2.0
            self.plugin_image = pyexiv2.Image(full_path)

            self.plugin_image.readMetadata()

            # get all KeyTags for this section of tags and if there is a value?
            MediaDataTags = [KeyTag for KeyTag in self.plugin_image.exifKeys()
                    if KeyTag in metadataTags ]

            # get all KeyTags for this section of tags and if there is a value?
            MediaDataTags.append( [KeyTag for KeyTag in self.plugin_image.xmpKeys()
                    if KeyTag in metadataTags ] )

            # get all KeyTags for this section of tags and if there is a value?
            MediaDataTags.append( [KeyTag for KeyTag in self.plugin_image.iptcKeys()
                    if KeyTag in metadataTags ] )

        else: # pyexiv2-0.2.0 and above