Skip to content

Commit

Permalink
v1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
r0x0r committed Jan 21, 2015
1 parent 79be260 commit e2e76a1
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 29 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.3
- `New` Support for resizing big sized photos (--big switch)
- `New` Ability to choose JPEG quality (--quality switch)
- `New` Support for uploading original unmodified files (--originals switch).


## 1.2.5
- `New` Support for medium sized files introduced in Lychee 2.7
- `Improved` Decreased the quality of generated thumbnails for smaller thumbnail sizes
Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,15 @@ Finally install dependencies using *pip*
General options

- `username@hostname:path` Server connection string with a full path to the directory where Lychee is installed.
- `-h`, `--help` show a help message
- `-r`, `--replace` replace albums in Lychee with local ones
- `-p`, `--public` make uploaded photos public
- `-v`, `--verbose` print verbose messages
- `-h`, `--help` Show a help message
- `-r`, `--replace` Replace albums in Lychee with local ones
- `-p`, `--public` Make uploaded photos public
- `-v`, `--verbose` Print verbose messages
- `--medium` Maximum size for medium sized pictures. 1920px by default.
- `--big` Maximum size for big sized pictures. By default pictures are untouched.
- `--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.

Directory import options
Directory import options

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

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

At very least you must specify a connection string and a source where photos should be imported from (`--dir`, `--iphoto` or `--aperture` options).
Expand Down
2 changes: 1 addition & 1 deletion database.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def loadAlbumList(self):
for row in rows:
self.albumslist[row[0]] = row[1]

logger.debug(self.albumslist)
#logger.debug(self.albumslist)

return self.albumslist

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

if conf.osx:
add_mac_arguments(parser, source_group)
Expand All @@ -72,7 +75,7 @@ def parse_arguments():
conf.public = args.public

if args.verbose:
conf.verbose = logging.INFO
conf.verbose = logging.DEBUG

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

if args.quality:
conf.quality = args.quality
else:
conf.quality = 70

if args.medium:
conf.medium_size = args.medium
else:
conf.medium_size = 1920

if args.big:
conf.big_size = args.big

if args.originals and args.big:
conf.upload_originals = True

if conf.osx:
if not parse_mac_arguments(args):
return False
Expand Down Expand Up @@ -192,8 +211,7 @@ def add_mac_arguments(parser, group):
help="Export matching smart albums. The argument is a regular expression. "
"If the argument is omitted, then all events are exported.")

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


Expand Down
30 changes: 21 additions & 9 deletions photo.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class LycheePhoto:
SMALL_THUMB_SIZE = (200, 200)
BIG_THUMB_SIZE = (400, 400)
MEDIUM_SIZE = (1920.0, 1080.0)
JPG_QUALITY = 80


def __init__(self, full_path, album_id):
Expand Down Expand Up @@ -142,22 +141,35 @@ def __init__(self, full_path, album_id):

self.thumbnailfullpath = self.generateThumbnail(self.SMALL_THUMB_SIZE)
self.thumbnailx2fullpath = self.generateThumbnail(self.BIG_THUMB_SIZE)
self.medium_path = self.generateMediumRes(self.MEDIUM_SIZE)
self.medium_path = self.resize(conf.medium_size)

if "big_size" in dir(conf):
self.big_path = self.resize(conf.big_size)
else:
self.big_path = self.srcfullpath

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


def generateMediumRes(self, res):
def resize(self, size):
with tempfile.NamedTemporaryFile(delete=False) as temp_image:

img = Image.open(self.srcfullpath)
ratio = min(res[0] / img.size[0], res[1] / img.size[1])
new_size = tuple(int(ratio * size) for size in img.size)
max_dimension = max(img.size[0], img.size[1])

if size < max_dimension:
ratio = float(size) / max_dimension
new_size = tuple(int(ratio * size) for size in img.size)
logger.debug("Original size: {}x{}; New size: {}x{}".format(img.size[0], img.size[1], new_size[0], new_size[1]))

medium_img = img.resize(new_size, Image.ANTIALIAS)
medium_img.save(temp_image.name, "JPEG", quality=self.JPG_QUALITY)
resized_img = img.resize(new_size, Image.ANTIALIAS)
resized_img.save(temp_image.name, "JPEG", quality=conf.quality)

return temp_image.name
return temp_image.name
else:
logger.debug("No resize needed. Image unchanged")
return self.srcfullpath


def generateThumbnail(self, res):
Expand Down Expand Up @@ -188,7 +200,7 @@ def generateThumbnail(self, res):
img = Image.open(self.srcfullpath)
img = img.crop((left, upper, right, lower))
img.thumbnail(res, Image.ANTIALIAS)
img.save(destimage, "JPEG", quality=self.JPG_QUALITY)
img.save(destimage, "JPEG", quality=conf.quality)
return destimage


Expand Down
15 changes: 11 additions & 4 deletions upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,18 @@ def uploadPhoto(self, photo):

try:
thumbnail_path = os.path.join(conf.path, "uploads", "thumb")
medium_path = os.path.join(conf.path, "uploads", "medium")
medium_path = os.path.join(conf.path, "uploads", "medium", photo.url)
import_path = os.path.join(conf.path, "uploads", "import", photo.url)

# upload photo
self.ssh.put(photo.srcfullpath, photo.destfullpath)
self.ssh.put(photo.medium_path, os.path.join(medium_path, photo.url))
# if the big flag is set, upload the resized photo to the big directory and the original photo into the
# import directory
if "big_size" in dir(conf):
self.ssh.put(photo.big_path, photo.destfullpath)

if "upload_originals" in dir(conf):
self.ssh.put(photo.srcfullpath, import_path)

self.ssh.put(photo.medium_path, medium_path)
self.ssh.put(photo.thumbnailfullpath, os.path.join(thumbnail_path, photo.url))
self.ssh.put(photo.thumbnailx2fullpath, os.path.join(thumbnail_path, photo.thumb2xUrl))

Expand Down

0 comments on commit e2e76a1

Please sign in to comment.