diff --git a/.gitignore b/.gitignore index 29b2b1d..51f7573 100644 --- a/.gitignore +++ b/.gitignore @@ -35,7 +35,7 @@ nosetests.xml .pydevproject tmptest/ -venv3.4/* +venv3.*/* venv2.7/* test/* logs/* diff --git a/lycheesync/lycheedao.py b/lycheesync/lycheedao.py index 5e837de..ead95f5 100644 --- a/lycheesync/lycheedao.py +++ b/lycheesync/lycheedao.py @@ -492,22 +492,22 @@ def addFileToAlbum(self, photo): "size, star, " + "thumbUrl, album,iso, aperture, make, " + "model, shutter, focal, takestamp, " + - "description, title, checksum) " + + "description, title, checksum, medium) " + "values " + "({}, '{}', {}, '{}', {}, {}, " + "'{}', {}, " + "'{}', '{}', '{}', '{}'," + " '{}', " + "'{}', '{}', '{}', '{}', " + - "'{}', %s, '{}')" - ).format(photo.id, photo.url, self.conf["publicAlbum"], photo.type, photo.width, photo.height, + "'{}', %s, '{}', '{}')" + ).format(photo.id, photo.url, photo.public, photo.type, photo.width, photo.height, photo.size, photo.star, photo.thumbUrl, photo.albumid, photo.exif.iso, photo.exif.aperture, photo.exif.make, photo.exif.model, photo.exif.shutter, photo.exif.focal, stamp, - photo.description, photo.checksum) + photo.description, photo.checksum, photo.medium) try: logger.debug(query) cur = self.db.cursor() diff --git a/lycheesync/lycheemodel.py b/lycheesync/lycheemodel.py index 0a26a9a..46f32c6 100644 --- a/lycheesync/lycheemodel.py +++ b/lycheesync/lycheemodel.py @@ -76,6 +76,7 @@ class LycheePhoto: description = "" url = "" public = 0 # private by default + medium = 0 # do not make medium thumbnail by default type = "" width = 0 height = 0 @@ -141,6 +142,9 @@ def __init__(self, id, conf, photoname, album): self.albumid = album['id'] self.albumname = album['name'] + self.public = self.conf["publicAlbum"]; + self.medium = self.conf["mediumThumb"]; + # if star in file name, photo is starred if ('star' in self.originalname) or ('cover' in self.originalname): self.star = 1 @@ -317,6 +321,7 @@ def __str__(self): res += "description:" + str(self.description) + "\n" res += "url:" + str(self.url) + "\n" res += "public:" + str(self.public) + "\n" + res += "medium:" + str(self.medium) + "\n" res += "type:" + str(self.type) + "\n" res += "width:" + str(self.width) + "\n" res += "height:" + str(self.height) + "\n" diff --git a/lycheesync/lycheesyncer.py b/lycheesync/lycheesyncer.py index c3979e3..8a091a4 100644 --- a/lycheesync/lycheesyncer.py +++ b/lycheesync/lycheesyncer.py @@ -92,7 +92,7 @@ def createAlbum(self, album): album['id'] = self.dao.createAlbum(album) return album['id'] - def thumbIt(self, res, photo, destinationpath, destfile): + def thumbIt(self, res, photo, destinationpath, destfile, crop): """ Create the thumbnail of a given photo Parameters: @@ -103,19 +103,6 @@ def thumbIt(self, res, photo, destinationpath, destfile): Returns the fullpath of the thuumbnail """ - if photo.width > photo.height: - delta = photo.width - photo.height - left = int(delta / 2) - upper = 0 - right = int(photo.height + left) - lower = int(photo.height) - else: - delta = photo.height - photo.width - left = 0 - upper = int(delta / 2) - right = int(photo.width) - lower = int(photo.width + upper) - destimage = os.path.join(destinationpath, destfile) try: img = Image.open(photo.destfullpath) @@ -124,11 +111,43 @@ def thumbIt(self, res, photo, destinationpath, destfile): logger.error("ioerror (corrupted file?): " + photo.srcfullpath) raise - img = img.crop((left, upper, right, lower)) + if (crop): + if photo.width > photo.height: + delta = photo.width - photo.height + left = int(delta / 2) + upper = 0 + right = int(photo.height + left) + lower = int(photo.height) + else: + delta = photo.height - photo.width + left = 0 + upper = int(delta / 2) + right = int(photo.width) + lower = int(photo.width + upper) + + img = img.crop((left, upper, right, lower)) + img.thumbnail(res, Image.ANTIALIAS) - img.save(destimage, quality=99) + 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.thumbIt(size, photo, destpath, destfile, False) + def makeThumbnail(self, photo): """ Make the 2 thumbnails needed by Lychee for a given photo @@ -145,8 +164,13 @@ def makeThumbnail(self, photo): # compute destination path destpath = os.path.join(self.conf["lycheepath"], "uploads", "thumb") # make thumbnails - photo.thumbnailfullpath = self.thumbIt(sizes[0], photo, destpath, destfiles[0]) - photo.thumbnailx2fullpath = self.thumbIt(sizes[1], photo, destpath, destfiles[1]) + photo.thumbnailfullpath = self.thumbIt(sizes[0], photo, destpath, destfiles[0], True) + photo.thumbnailx2fullpath = self.thumbIt(sizes[1], photo, destpath, destfiles[1], True) + + # make medium thumbnail if required + if (photo.medium): + self.makeMedium(photo) + def copyFileToLychee(self, photo): """ @@ -199,12 +223,14 @@ def deleteFiles(self, filelist): for url in filelist: if self.isAPhoto(url): thumbpath = os.path.join(self.conf["lycheepath"], "uploads", "thumb", url) + mediumpath = os.path.join(self.conf["lycheepath"], "uploads", "medium", url) filesplit = os.path.splitext(url) thumb2path = ''.join([filesplit[0], "@2x", filesplit[1]]).lower() thumb2path = os.path.join(self.conf["lycheepath"], "uploads", "thumb", thumb2path) bigpath = os.path.join(self.conf["lycheepath"], "uploads", "big", url) remove_file(thumbpath) remove_file(thumb2path) + remove_file(mediumpath) remove_file(bigpath) def adjustRotation(self, photo): diff --git a/ressources/conf.json b/ressources/conf.json index 3b72c13..07ae19c 100644 --- a/ressources/conf.json +++ b/ressources/conf.json @@ -6,6 +6,7 @@ "dbSocket":"/var/run/mysqld/mysqld.sock", "thumbQuality":80, "publicAlbum": 0, + "mediumThumb": 1, "excludeAlbums": [ ] } diff --git a/ressources/test_conf.json b/ressources/test_conf.json index 98091ac..ec7ed8d 100644 --- a/ressources/test_conf.json +++ b/ressources/test_conf.json @@ -5,6 +5,7 @@ "dbHost":"localhost", "thumbQuality":80, "publicAlbum": 0, + "mediumThumb": 1, "excludeAlbums": [], "lycheepath": "/tmp/lychee", "testphotopath": "./tmptest",