Skip to content

Commit 79be260

Browse files
committed
Support for medium sized files
1 parent f5fc1c2 commit 79be260

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.2.5
2+
- `New` Support for medium sized files introduced in Lychee 2.7
3+
- `Improved` Decreased the quality of generated thumbnails for smaller thumbnail sizes
4+
15
## 1.2
26
- `New` Support for importing directly from iPhoto / Aperture libraries
37

database.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,18 +218,18 @@ def addFileToAlbum(self, photo):
218218
"size, star, " +
219219
"thumbUrl, album, iso, aperture, make, " +
220220
"model, shutter, focal, takestamp, " +
221-
"description, title, checksum) " +
221+
"description, title, checksum, medium) " +
222222
"values " +
223223
"({}, '{}', {}, '{}', {}, {}, " +
224224
"'{}', {}, " +
225225
"'{}', '{}', '{}', '{}', '{}', " +
226226
"'{}', '{}', '{}', '{}', " +
227-
"'{}', '{}', '{}')"
227+
"'{}', '{}', '{}', {})"
228228
).format(photo.id, photo.url, conf.public, photo.type, photo.width, photo.height,
229229
photo.size, photo.star,
230230
photo.url, photo.albumid, photo.exif.iso, photo.exif.aperture, photo.exif.make,
231231
photo.exif.model, photo.exif.shutter, photo.exif.focal, photo.datetime.strftime("%s"),
232-
photo.description, photo.originalname, photo.checksum)
232+
photo.description, photo.originalname, photo.checksum, 1)
233233

234234
cur = self.db.cursor()
235235
cur.execute(query)

lycheeupload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/python
22
# -*- coding: utf-8 -*-
33
"""
4-
lychee upload v1.2
4+
lychee upload v1.2.5
55
(C) 2014 Roman Sirokov
66
77
Imports images from a location on hard drive to the Lychee installation on a remote server via SSH.

photo.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class LycheePhoto:
6363

6464
SMALL_THUMB_SIZE = (200, 200)
6565
BIG_THUMB_SIZE = (400, 400)
66+
MEDIUM_SIZE = (1920.0, 1080.0)
67+
JPG_QUALITY = 80
6668

6769

6870
def __init__(self, full_path, album_id):
@@ -140,11 +142,24 @@ def __init__(self, full_path, album_id):
140142

141143
self.thumbnailfullpath = self.generateThumbnail(self.SMALL_THUMB_SIZE)
142144
self.thumbnailx2fullpath = self.generateThumbnail(self.BIG_THUMB_SIZE)
145+
self.medium_path = self.generateMediumRes(self.MEDIUM_SIZE)
143146

144147
# Generate SHA1 hash
145148
self.checksum = self.generateHash(self.srcfullpath)
146149

147150

151+
def generateMediumRes(self, res):
152+
with tempfile.NamedTemporaryFile(delete=False) as temp_image:
153+
img = Image.open(self.srcfullpath)
154+
ratio = min(res[0] / img.size[0], res[1] / img.size[1])
155+
new_size = tuple(int(ratio * size) for size in img.size)
156+
157+
medium_img = img.resize(new_size, Image.ANTIALIAS)
158+
medium_img.save(temp_image.name, "JPEG", quality=self.JPG_QUALITY)
159+
160+
return temp_image.name
161+
162+
148163
def generateThumbnail(self, res):
149164
"""
150165
Create the thumbnail of a given photo
@@ -173,7 +188,7 @@ def generateThumbnail(self, res):
173188
img = Image.open(self.srcfullpath)
174189
img = img.crop((left, upper, right, lower))
175190
img.thumbnail(res, Image.ANTIALIAS)
176-
img.save(destimage, "JPEG", quality=99)
191+
img.save(destimage, "JPEG", quality=self.JPG_QUALITY)
177192
return destimage
178193

179194

@@ -182,6 +197,7 @@ def cleanup(self):
182197
Delete thumbnail files from the local disk. Called after the photo was successfully uploaded.
183198
"""
184199
try:
200+
os.remove(self.medium_path)
185201
os.remove(self.thumbnailfullpath)
186202
os.remove(self.thumbnailx2fullpath)
187203
except Exception:

upload.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,23 @@ def uploadPhoto(self, photo):
5454
file_name = os.path.basename(photo.srcfullpath)
5555

5656
try:
57-
thumbnailPath = os.path.join(conf.path, "uploads", "thumb")
57+
thumbnail_path = os.path.join(conf.path, "uploads", "thumb")
58+
medium_path = os.path.join(conf.path, "uploads", "medium")
5859

5960
# upload photo
6061
self.ssh.put(photo.srcfullpath, photo.destfullpath)
61-
self.ssh.put(photo.thumbnailfullpath, os.path.join(thumbnailPath, photo.url))
62-
self.ssh.put(photo.thumbnailx2fullpath, os.path.join(thumbnailPath, photo.thumb2xUrl))
62+
self.ssh.put(photo.medium_path, os.path.join(medium_path, photo.url))
63+
self.ssh.put(photo.thumbnailfullpath, os.path.join(thumbnail_path, photo.url))
64+
self.ssh.put(photo.thumbnailx2fullpath, os.path.join(thumbnail_path, photo.thumb2xUrl))
6365

6466
if self.dao.addFileToAlbum(photo):
6567
logger.info("Uploaded file {}/{}".format(album_name, file_name))
6668
return True
6769
else:
6870
self.ssh.remove(photo.destfullpath)
69-
self.ssh.remove(os.path.join(thumbnailPath, photo.url))
70-
self.ssh.remove(os.path.join(thumbnailPath, photo.thumb2xUrl))
71+
self.ssh.remove(os.path.join(medium_path, photo.url))
72+
self.ssh.remove(os.path.join(thumbnail_path, photo.url))
73+
self.ssh.remove(os.path.join(thumbnail_path, photo.thumb2xUrl))
7174

7275
return False
7376

0 commit comments

Comments
 (0)