Skip to content

Commit e2e76a1

Browse files
committed
v1.3
1 parent 79be260 commit e2e76a1

File tree

6 files changed

+74
-29
lines changed

6 files changed

+74
-29
lines changed

Diff for: CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 1.3
2+
- `New` Support for resizing big sized photos (--big switch)
3+
- `New` Ability to choose JPEG quality (--quality switch)
4+
- `New` Support for uploading original unmodified files (--originals switch).
5+
6+
17
## 1.2.5
28
- `New` Support for medium sized files introduced in Lychee 2.7
39
- `Improved` Decreased the quality of generated thumbnails for smaller thumbnail sizes

Diff for: README.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,15 @@ Finally install dependencies using *pip*
4747
General options
4848

4949
- `username@hostname:path` Server connection string with a full path to the directory where Lychee is installed.
50-
- `-h`, `--help` show a help message
51-
- `-r`, `--replace` replace albums in Lychee with local ones
52-
- `-p`, `--public` make uploaded photos public
53-
- `-v`, `--verbose` print verbose messages
50+
- `-h`, `--help` Show a help message
51+
- `-r`, `--replace` Replace albums in Lychee with local ones
52+
- `-p`, `--public` Make uploaded photos public
53+
- `-v`, `--verbose` Print verbose messages
54+
- `--medium` Maximum size for medium sized pictures. 1920px by default.
55+
- `--big` Maximum size for big sized pictures. By default pictures are untouched.
56+
- `--originals` Upload original untouched files. To be used with the --big option, otherwise ignored. Files are place inside import directory. Note that this option is not currently supported by Lychee and is useful if you want to reduce the size of your big pictures, while still preserving originals.
5457

55-
Directory import options
58+
Directory import options
5659

5760
- `-d DIR`, `--dir DIR` path to the photo directory where to export photos from.
5861

@@ -63,7 +66,6 @@ iPhoto / Aperture options
6366
- `-e [pattern]`, `--events [pattern]` Export matching events. The argument is a regular expression. If the argument is omitted, then all events are exported.
6467
- `-a [pattern]`, `--albums [pattern]` Export matching regular albums. The argument is a regular expression. If the argument is omitted, then all events are exported.
6568
- `-s [pattern]`, `--smarts [pattern]` Export matching smart albums. The argument is a regular expression. If the argument is omitted, then all events are exported.
66-
- `--originals` Export originals instead of modified images
6769
- `-x pattern`, `--exclude pattern` Don't export matching albums or events. The pattern is a regular expression.
6870

6971
At very least you must specify a connection string and a source where photos should be imported from (`--dir`, `--iphoto` or `--aperture` options).

Diff for: database.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def loadAlbumList(self):
9999
for row in rows:
100100
self.albumslist[row[0]] = row[1]
101101

102-
logger.debug(self.albumslist)
102+
#logger.debug(self.albumslist)
103103

104104
return self.albumslist
105105

Diff for: lycheeupload.py

+27-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/bin/python
22
# -*- coding: utf-8 -*-
33
"""
4-
lychee upload v1.2.5
5-
(C) 2014 Roman Sirokov
4+
lychee upload v1.3
5+
(C) 2014-2015 Roman Sirokov
66
77
Imports images from a location on hard drive to the Lychee installation on a remote server via SSH.
88
@@ -58,10 +58,13 @@ def parse_arguments():
5858
parser.add_argument('-r', '--replace', help="replace albums in Lychee with local ones", action='store_true')
5959
parser.add_argument('-p', '--public', help="make uploaded photos public", action='store_true')
6060
parser.add_argument('-v', '--verbose', help='print verbose messages', action='store_true')
61-
"""
62-
parser.add_argument('--size', help="Resize images so that neither width or height exceeds this size. "
63-
"Converts all images to jpeg.", type=str)
64-
"""
61+
parser.add_argument('-q', '--quality', help='JPEG quality 0-99 for resized pictures', type=int)
62+
parser.add_argument('--medium', help='Maximum size for medium sized pictures. 1920px by default', type=int)
63+
parser.add_argument('--big', help='Maximum size for big sized pictures. By default pictures are untouched ',
64+
type=int)
65+
parser.add_argument('--originals',
66+
help='Upload original untouched files. To be used with the --big option, otherwise ignored.',
67+
action='store_true')
6568

6669
if conf.osx:
6770
add_mac_arguments(parser, source_group)
@@ -72,7 +75,7 @@ def parse_arguments():
7275
conf.public = args.public
7376

7477
if args.verbose:
75-
conf.verbose = logging.INFO
78+
conf.verbose = logging.DEBUG
7679

7780
if args.server:
7881
if not parse_server_string(args.server[0]):
@@ -89,6 +92,22 @@ def parse_arguments():
8992
logger.error("Please specify a directory to export photos from")
9093
return False
9194

95+
if args.quality:
96+
conf.quality = args.quality
97+
else:
98+
conf.quality = 70
99+
100+
if args.medium:
101+
conf.medium_size = args.medium
102+
else:
103+
conf.medium_size = 1920
104+
105+
if args.big:
106+
conf.big_size = args.big
107+
108+
if args.originals and args.big:
109+
conf.upload_originals = True
110+
92111
if conf.osx:
93112
if not parse_mac_arguments(args):
94113
return False
@@ -192,8 +211,7 @@ def add_mac_arguments(parser, group):
192211
help="Export matching smart albums. The argument is a regular expression. "
193212
"If the argument is omitted, then all events are exported.")
194213

195-
parser.add_argument('--originals', help='Export originals instead of modified images', action="store_true")
196-
parser.add_argument('-x', '--exclude', metavar="pattern", type=str,
214+
parser.add_argument('-x', '--exclude', metavar="pattern", type=str,
197215
help="Don't export matching albums or events. The pattern is a regular expression.")
198216

199217

Diff for: photo.py

+21-9
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ class LycheePhoto:
6464
SMALL_THUMB_SIZE = (200, 200)
6565
BIG_THUMB_SIZE = (400, 400)
6666
MEDIUM_SIZE = (1920.0, 1080.0)
67-
JPG_QUALITY = 80
6867

6968

7069
def __init__(self, full_path, album_id):
@@ -142,22 +141,35 @@ def __init__(self, full_path, album_id):
142141

143142
self.thumbnailfullpath = self.generateThumbnail(self.SMALL_THUMB_SIZE)
144143
self.thumbnailx2fullpath = self.generateThumbnail(self.BIG_THUMB_SIZE)
145-
self.medium_path = self.generateMediumRes(self.MEDIUM_SIZE)
144+
self.medium_path = self.resize(conf.medium_size)
145+
146+
if "big_size" in dir(conf):
147+
self.big_path = self.resize(conf.big_size)
148+
else:
149+
self.big_path = self.srcfullpath
146150

147151
# Generate SHA1 hash
148152
self.checksum = self.generateHash(self.srcfullpath)
149153

150154

151-
def generateMediumRes(self, res):
155+
def resize(self, size):
152156
with tempfile.NamedTemporaryFile(delete=False) as temp_image:
157+
153158
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)
159+
max_dimension = max(img.size[0], img.size[1])
160+
161+
if size < max_dimension:
162+
ratio = float(size) / max_dimension
163+
new_size = tuple(int(ratio * size) for size in img.size)
164+
logger.debug("Original size: {}x{}; New size: {}x{}".format(img.size[0], img.size[1], new_size[0], new_size[1]))
156165

157-
medium_img = img.resize(new_size, Image.ANTIALIAS)
158-
medium_img.save(temp_image.name, "JPEG", quality=self.JPG_QUALITY)
166+
resized_img = img.resize(new_size, Image.ANTIALIAS)
167+
resized_img.save(temp_image.name, "JPEG", quality=conf.quality)
159168

160-
return temp_image.name
169+
return temp_image.name
170+
else:
171+
logger.debug("No resize needed. Image unchanged")
172+
return self.srcfullpath
161173

162174

163175
def generateThumbnail(self, res):
@@ -188,7 +200,7 @@ def generateThumbnail(self, res):
188200
img = Image.open(self.srcfullpath)
189201
img = img.crop((left, upper, right, lower))
190202
img.thumbnail(res, Image.ANTIALIAS)
191-
img.save(destimage, "JPEG", quality=self.JPG_QUALITY)
203+
img.save(destimage, "JPEG", quality=conf.quality)
192204
return destimage
193205

194206

Diff for: upload.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,18 @@ def uploadPhoto(self, photo):
5555

5656
try:
5757
thumbnail_path = os.path.join(conf.path, "uploads", "thumb")
58-
medium_path = os.path.join(conf.path, "uploads", "medium")
58+
medium_path = os.path.join(conf.path, "uploads", "medium", photo.url)
59+
import_path = os.path.join(conf.path, "uploads", "import", photo.url)
5960

60-
# upload photo
61-
self.ssh.put(photo.srcfullpath, photo.destfullpath)
62-
self.ssh.put(photo.medium_path, os.path.join(medium_path, photo.url))
61+
# if the big flag is set, upload the resized photo to the big directory and the original photo into the
62+
# import directory
63+
if "big_size" in dir(conf):
64+
self.ssh.put(photo.big_path, photo.destfullpath)
65+
66+
if "upload_originals" in dir(conf):
67+
self.ssh.put(photo.srcfullpath, import_path)
68+
69+
self.ssh.put(photo.medium_path, medium_path)
6370
self.ssh.put(photo.thumbnailfullpath, os.path.join(thumbnail_path, photo.url))
6471
self.ssh.put(photo.thumbnailx2fullpath, os.path.join(thumbnail_path, photo.thumb2xUrl))
6572

0 commit comments

Comments
 (0)