From b6574906278d6b78395f17fd41c00384abdc0a0f Mon Sep 17 00:00:00 2001 From: palitu Date: Thu, 19 Nov 2015 20:58:23 +0800 Subject: [PATCH] Update lycheesyncer.py Creates medium sized photo. --- lycheesyncer.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/lycheesyncer.py b/lycheesyncer.py index 934cedc..66dd0c7 100644 --- a/lycheesyncer.py +++ b/lycheesyncer.py @@ -131,6 +131,46 @@ def makeThumbnail(self, photo): photo.thumbnailfullpath = self.thumbIt(sizes[0], photo, destpath, destfiles[0]) photo.thumbnailx2fullpath = self.thumbIt(sizes[1], photo, destpath, destfiles[1]) + def mediumIt(self, res, photo, destinationpath, destfile): + """ + Create the medium sized image of a given photo + Parameters: + - res: should be a set of h and v res - which matches lychee (640, 480) + - photo: a valid LycheePhoto object + - destinationpath: a string the destination full path of the medium photo (without filename) + - destfile: the medium photo filename + Returns the fullpath of the medium photo + """ + + destimage = os.path.join(destinationpath, destfile) + try: + img = Image.open(photo.srcfullpath) + except: + print "ERROR ioerror (corrupted file?): " + photo.srcfullpath + raise + + # img = img.crop((left, upper, right, lower)) + img.thumbnail(res, Image.ANTIALIAS) + img.save(destimage, quality=90) + return destimage + + def makeMedium(self, photo): + """ + Make medium photo used by Lychee for a given photo + and store their path in the LycheePhoto object + Parameters: + - photo: a valid LycheePhoto object + returns nothing + """ + # set medium photo size + size = 1920, 1080 + # set medium photo file name + destfile = photo.url + # compute destination path + destpath = os.path.join(self.conf["lycheepath"], "uploads", "medium") + # make medium photo + photo.mediumfullpath = self.mediumIt(size, photo, destpath, destfile) + def addFileToAlbum(self, photo): """ add a file to an album, the albumid must be previously stored in the LycheePhoto parameter @@ -355,6 +395,7 @@ def sync(self): if self.conf['verbose']: print "INFO: adding to lychee", os.path.join(root, f) self.makeThumbnail(photo) + self.makeMedium(photo) res = self.addFileToAlbum(photo) self.adjustRotation(photo) # increment counter