Esempio n. 1
0
File: db.py Progetto: peircej/jbrout
    def getInfoFrom(self, copy):
        """ rewrite info from a 'copy' to the file (exif, iptc, ...)
            and rebuild thumb
            (used to ensure everything is back after a run in another program
             see plugin 'touch')
        """
        pc = PhotoCmd(copy)
        pc.copyInfoTo(self.file)

        #and update infos
        # generally, it's not necessary ... but if size had changed, jhead
        # correct automatically width/height exif, so we need to put back in db
        pc = PhotoCmd(self.file)
        self.updateInfo(pc)
Esempio n. 2
0
File: db.py Progetto: peircej/jbrout
    def getInfoFrom(self, copy):
        """ rewrite info from a 'copy' to the file (exif, iptc, ...)
            and rebuild thumb
            (used to ensure everything is back after a run in another program
             see plugin 'touch')
        """
        pc = PhotoCmd(copy)
        pc.copyInfoTo(self.file)

        #and update infos
        # generally, it's not necessary ... but if size had changed, jhead
        # correct automatically width/height exif, so we need to put back in db
        pc = PhotoCmd(self.file)
        self.updateInfo(pc)
Esempio n. 3
0
File: db.py Progetto: peircej/jbrout
    def copyTo(self, path, resize=None, keepInfo=True, delTags=False,
               delCom=False):
        """ copy self to the path "path", and return its newfilename or none
            by default, it keeps IPTC/THUMB/EXIF, but it can be removed by
            setting keepInfo at False. In all case, new file keep its filedate
            system

            image can be resized/recompressed (preserving ratio) if resize
            (which is a tuple=(size, qual)) is provided:
                if size is a float : it's a percent of original
                if size is a int : it's the desired largest side
                qual : is the percent for the quality
        """
        assert type(path) == unicode, "photonod.copyTo() : path is not unicode"
        dest = os.path.join(path, self.name)

        while os.path.isfile(dest):
            dest = os.path.join(path,
                                PhotoCmd.giveMeANewName(
                                    os.path.basename(dest)))

        if resize:
            assert len(resize) == 2
            size, qual = resize
            assert type(size) in [int, float]

            pb = self.getImage()  # a gtk.PixBuf
            (wx, wy) = pb.get_width(), pb.get_height()

            # compute the new size -> wx/wy
            if type(size) == float:
                # size is a percent
                size = int(size * 100)
                wx = int(wx * size / 100)
                wy = int(wy * size / 100)

            else:
                # size is the largest side in pixels
                if wx > wy:
                    # format landscape
                    wx, wy = size, (size * wy) / wx
                else:
                    # format portrait
                    wx, wy = (size * wx) / wy, size

            # 3= best quality (gtk.gdk.INTERP_HYPER)
            pb = pb.scale_simple(wx, wy, 3)
            pb.save(dest, "jpeg", {"quality": str(int(qual))})

            if keepInfo:
                pc = PhotoCmd(self.file)
                pc.copyInfoTo(dest)
            del(pb)
            gc.collect()  # so it cleans pixbufs
        else:
            shutil.copy2(self.file, dest)
            if not keepInfo:
                # we must destroy info
                PhotoCmd(dest).destroyInfo()
        if keepInfo:
            if delCom:
                PhotoCmd(dest).addComment(u"")
            if delTags:
                PhotoCmd(dest).clear()

        return dest
Esempio n. 4
0
File: db.py Progetto: peircej/jbrout
    def copyTo(self,
               path,
               resize=None,
               keepInfo=True,
               delTags=False,
               delCom=False):
        """ copy self to the path "path", and return its newfilename or none
            by default, it keeps IPTC/THUMB/EXIF, but it can be removed by
            setting keepInfo at False. In all case, new file keep its filedate
            system

            image can be resized/recompressed (preserving ratio) if resize
            (which is a tuple=(size, qual)) is provided:
                if size is a float : it's a percent of original
                if size is a int : it's the desired largest side
                qual : is the percent for the quality
        """
        assert type(path) == unicode, "photonod.copyTo() : path is not unicode"
        dest = os.path.join(path, self.name)

        while os.path.isfile(dest):
            dest = os.path.join(
                path, PhotoCmd.giveMeANewName(os.path.basename(dest)))

        if resize:
            assert len(resize) == 2
            size, qual = resize
            assert type(size) in [int, float]

            pb = self.getImage()  # a gtk.PixBuf
            (wx, wy) = pb.get_width(), pb.get_height()

            # compute the new size -> wx/wy
            if type(size) == float:
                # size is a percent
                size = int(size * 100)
                wx = int(wx * size / 100)
                wy = int(wy * size / 100)

            else:
                # size is the largest side in pixels
                if wx > wy:
                    # format landscape
                    wx, wy = size, (size * wy) / wx
                else:
                    # format portrait
                    wx, wy = (size * wx) / wy, size

            # 3= best quality (gtk.gdk.INTERP_HYPER)
            pb = pb.scale_simple(wx, wy, 3)
            pb.save(dest, "jpeg", {"quality": str(int(qual))})

            if keepInfo:
                pc = PhotoCmd(self.file)
                pc.copyInfoTo(dest)
            del (pb)
            gc.collect()  # so it cleans pixbufs
        else:
            shutil.copy2(self.file, dest)
            if not keepInfo:
                # we must destroy info
                PhotoCmd(dest).destroyInfo()
        if keepInfo:
            if delCom:
                PhotoCmd(dest).addComment(u"")
            if delTags:
                PhotoCmd(dest).clear()

        return dest