add a thumb_suffix setting and create a function to get the path of a thumbnail
This commit is contained in:
@@ -31,6 +31,7 @@ import PIL
|
||||
from clint.textui import progress
|
||||
|
||||
from .image import Image, copy_exif
|
||||
from .settings import get_thumb
|
||||
from .writer import Writer
|
||||
|
||||
DESCRIPTION_FILE = "index.md"
|
||||
@@ -113,8 +114,8 @@ class Gallery:
|
||||
def process_dir(self, imglist, img_out):
|
||||
"Process images for a directory"
|
||||
|
||||
thumb_dir = os.path.join(img_out, self.settings['thumb_dir'])
|
||||
check_or_create_dir(thumb_dir)
|
||||
# Create thumbnails directory and optionally the one for original img
|
||||
check_or_create_dir(os.path.join(img_out, self.settings['thumb_dir']))
|
||||
|
||||
if self.settings['big_img']:
|
||||
bigimg_dir = os.path.join(img_out, self.settings['bigimg_dir'])
|
||||
@@ -144,8 +145,8 @@ class Gallery:
|
||||
img.save(im_name, quality=self.settings['jpg_quality'])
|
||||
|
||||
if self.settings['make_thumbs']:
|
||||
thumb_name = os.path.join(
|
||||
thumb_dir, self.settings['thumb_prefix'] + filename)
|
||||
thumb_name = os.path.join(img_out,
|
||||
get_thumb(self.settings, filename))
|
||||
img.thumbnail(thumb_name, self.settings['thumb_size'],
|
||||
fit=self.settings['thumb_fit'],
|
||||
quality=self.settings['jpg_quality'])
|
||||
|
||||
@@ -27,7 +27,8 @@ import os
|
||||
_DEFAULT_CONFIG = {
|
||||
'img_size': '640x480',
|
||||
'make_thumbs': 1,
|
||||
'thumb_prefix': 'TN-',
|
||||
'thumb_prefix': '',
|
||||
'thumb_suffix': '',
|
||||
'thumb_size': '150x112',
|
||||
'thumb_dir': '',
|
||||
'thumb_fit': 1,
|
||||
@@ -42,7 +43,7 @@ _DEFAULT_CONFIG = {
|
||||
|
||||
|
||||
def get_size(string):
|
||||
"split size string to a tuple of int"
|
||||
"Split size string to a tuple of int"
|
||||
|
||||
size = [int(i) for i in string.split("x")]
|
||||
if size[1] > size[0]:
|
||||
@@ -50,6 +51,14 @@ def get_size(string):
|
||||
return tuple(size)
|
||||
|
||||
|
||||
def get_thumb(settings, filename):
|
||||
"Return the path to the thumb"
|
||||
|
||||
name, ext = os.path.splitext(filename)
|
||||
return os.path.join(settings['thumb_dir'], settings['thumb_prefix'] +
|
||||
name + settings['thumb_suffix'] + ext)
|
||||
|
||||
|
||||
def read_settings(filename=None):
|
||||
"Read settings from a config file in the source_dir root"
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ from distutils.dir_util import copy_tree
|
||||
from jinja2 import Environment, PackageLoader
|
||||
|
||||
from .image import Image
|
||||
from .settings import get_thumb
|
||||
|
||||
INDEX_PAGE = "index.html"
|
||||
SIGAL_LINK = "https://github.com/saimn/sigal"
|
||||
@@ -107,16 +108,13 @@ class Writer():
|
||||
for i in paths[relpath]['img']:
|
||||
ctx['images'].append({
|
||||
'file': i,
|
||||
'thumb': os.path.join(self.settings['thumb_dir'],
|
||||
self.settings['thumb_prefix'] + i)
|
||||
'thumb': get_thumb(self.settings, i)
|
||||
})
|
||||
|
||||
for d in paths[relpath]['subdir']:
|
||||
dpath = os.path.normpath(os.path.join(relpath, d))
|
||||
alb_thumb = paths[dpath]['representative']
|
||||
thumb_name = os.path.join(self.settings['thumb_dir'],
|
||||
self.settings['thumb_prefix'] +
|
||||
alb_thumb)
|
||||
thumb_name = get_thumb(self.settings, alb_thumb)
|
||||
thumb_path = os.path.join(self.output_dir, dpath, thumb_name)
|
||||
|
||||
# generate the thumbnail if it is missing (if
|
||||
|
||||
@@ -13,7 +13,8 @@ make_thumbs = 1
|
||||
thumb_dir = thumbnail
|
||||
|
||||
# prefix for thumbnails name
|
||||
thumb_prefix = tn-
|
||||
thumb_prefix =
|
||||
thumb_suffix = .tn
|
||||
|
||||
# thumbnail size
|
||||
thumb_size = 200x150
|
||||
|
||||
Reference in New Issue
Block a user