Skip to content

Commit

Permalink
Merge 8627c1b into 043bc70
Browse files Browse the repository at this point in the history
  • Loading branch information
ru-voland committed Feb 17, 2018
2 parents 043bc70 + 8627c1b commit a24c5cd
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -35,7 +35,7 @@ nosetests.xml
.pydevproject

tmptest/
venv3.4/*
venv3.*/*
venv2.7/*
test/*
logs/*
Expand Down
8 changes: 4 additions & 4 deletions lycheesync/lycheedao.py
Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions lycheesync/lycheemodel.py
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
62 changes: 44 additions & 18 deletions lycheesync/lycheesyncer.py
Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions ressources/conf.json
Expand Up @@ -6,6 +6,7 @@
"dbSocket":"/var/run/mysqld/mysqld.sock",
"thumbQuality":80,
"publicAlbum": 0,
"mediumThumb": 1,
"excludeAlbums": [
]
}
Expand Down
1 change: 1 addition & 0 deletions ressources/test_conf.json
Expand Up @@ -5,6 +5,7 @@
"dbHost":"localhost",
"thumbQuality":80,
"publicAlbum": 0,
"mediumThumb": 1,
"excludeAlbums": [],
"lycheepath": "/tmp/lychee",
"testphotopath": "./tmptest",
Expand Down

0 comments on commit a24c5cd

Please sign in to comment.