Browse Source

Fix #118: allow passthrough of original files

pull/119/head
Antoine Pitrou 12 years ago
parent
commit
e5b7e53e51
  1. 3
      sigal/gallery.py
  2. 7
      sigal/image.py
  3. 1
      sigal/settings.py
  4. 44
      sigal/templates/sigal.conf.py
  5. 5
      tests/test_gallery.py
  6. 24
      tests/test_image.py

3
sigal/gallery.py

@ -95,6 +95,9 @@ class Media(UnicodeMixin):
"""
if self.settings['keep_orig']:
s = self.settings
if s['use_orig']:
# The image *is* the original, just use it
return self.filename
orig_path = join(s['destination'], self.path, s['orig_dir'])
check_or_create_dir(orig_path)
copy(self.src_path, join(orig_path, self.src_filename),

7
sigal/image.py

@ -42,7 +42,7 @@ from PIL import ImageOps
from pilkit.processors import Transpose
from pilkit.utils import save_image
from . import compat, signals
from . import compat, signals, utils
from .settings import get_thumb, Status
@ -61,6 +61,11 @@ def generate_image(source, outname, settings, options=None):
"""
logger = logging.getLogger(__name__)
if settings['use_orig']:
utils.copy(source, outname, symlink=settings['orig_link'])
return
img = PILImage.open(source)
original_format = img.format

1
sigal/settings.py

@ -62,6 +62,7 @@ _DEFAULT_CONFIG = {
'thumb_size': (200, 150),
'thumb_suffix': '',
'title': '',
'use_orig': False,
'video_size': (480, 360),
'webm_options': ['-crf', '10', '-b:v', '1.6M',
'-qmin', '4', '-qmax', '63'],

44
sigal/templates/sigal.conf.py

@ -9,6 +9,10 @@
# The priority order is: cli option > settings file > index.md file
# title = "Sigal test gallery"
# ---------------------
# General configuration
# ---------------------
# Source directory. Can be set here or as the first argument of the `sigal
# build` command
source = 'pictures'
@ -21,6 +25,16 @@ source = 'pictures'
# - colorbox (default), galleria, or the path to a custom theme directory
theme = 'galleria'
# Use originals in gallery (default: False). If True, this will bypass all
# processing steps (resize, auto-orient, recompress, and any plugin-specific
# step).
# Originals will be symlinked if orig_link = True, else they will be copied.
# use_orig = False
# ----------------
# Image processing (ignored if use_orig = True)
# ----------------
# Size of resized image (default: (640, 480))
img_size = (800, 600)
@ -32,6 +46,19 @@ img_size = (800, 600)
# - None: don't resize
# img_processor = 'ResizeToFit'
# Autorotate images
# Warning: this setting is not compatible with `copy_exif_data` (see below),
# because Sigal can't save the modified Orientation tag (currently Pillow can't
# write EXIF).
# autorotate_images = True
# If True, EXIF data from the original image is copied to the resized image
# copy_exif_data = False
# --------------------
# Thumbnail generation
# --------------------
# Generate thumbnails
# make_thumbs = True
@ -50,6 +77,10 @@ thumb_size = (280, 210)
# Crop the image to fill the box
# thumb_fit = True
# -------------
# Album options
# -------------
# Keep original image (default: False)
# keep_orig = True
@ -76,6 +107,10 @@ thumb_size = (280, 210)
ignore_directories = []
ignore_files = []
# -------------
# Miscellaneous
# -------------
# Jpeg options
# jpg_options = {'quality': 85,
# 'optimize': True,
@ -110,15 +145,6 @@ ignore_files = []
# zip_gallery = False # False or 'archive.zip'
# zip_media_format = 'resized' # 'resized' or 'orig'
# Autorotate images
# Warning: this setting is not compatible with `copy_exif_data` (see below),
# because Sigal can't save the modified Orientation tag (currently Pillow can't
# write EXIF).
# autorotate_images = True
# If True, EXIF data from the original image is copied to the resized image
# copy_exif_data = False
# Specify a different locale. If set to '', the default locale is used.
# locale = ''

5
tests/test_gallery.py

@ -95,6 +95,11 @@ def test_media_orig(settings, tmpdir):
assert m.big == 'original/stallman software-freedom-day-low.ogv'
assert os.path.isfile(join(settings['destination'], m.path, m.big))
settings['use_orig'] = True
m = Image('21.jpg', 'dir1/test2', settings)
assert m.big == '21.jpg'
def test_image(settings, tmpdir):
settings['destination'] = str(tmpdir)

24
tests/test_image.py

@ -25,6 +25,30 @@ def test_generate_image(tmpdir):
assert im.size == size
def test_generate_image_passthrough(tmpdir):
"Test the generate_image function with use_orig=True."
dstfile = str(tmpdir.join(TEST_IMAGE))
settings = create_settings(use_orig=True)
generate_image(SRCFILE, dstfile, settings)
# Check the file was copied, not (sym)linked
st_src = os.stat(SRCFILE)
st_dst = os.stat(dstfile)
assert st_src.st_size == st_dst.st_size
assert not os.path.samestat(st_src, st_dst)
def test_generate_image_passthrough_symlink(tmpdir):
"Test the generate_image function with use_orig=True and orig_link=True."
dstfile = str(tmpdir.join(TEST_IMAGE))
settings = create_settings(use_orig=True, orig_link=True)
generate_image(SRCFILE, dstfile, settings)
# Check the file was symlinked
assert os.path.islink(dstfile)
assert os.path.samefile(SRCFILE, dstfile)
def test_generate_image_processor(tmpdir):
"Test generate_image with a wrong processor name."

Loading…
Cancel
Save