Add a setting to choose the pilkit processor used to resize the images.
This commit is contained in:
@@ -238,7 +238,8 @@ def process_image(filepath, outpath, settings):
|
||||
shutil.copy(filepath, join(outpath, settings['orig_dir'], filename))
|
||||
|
||||
generate_image(filepath, outname, settings['img_size'], None,
|
||||
options=options, copyright_text=settings['copyright'])
|
||||
options=options, copyright_text=settings['copyright'],
|
||||
method=settings['img_processor'])
|
||||
|
||||
if settings['make_thumbs']:
|
||||
thumb_name = join(outpath, get_thumb(settings, filename))
|
||||
|
||||
@@ -21,14 +21,17 @@
|
||||
# IN THE SOFTWARE.
|
||||
|
||||
import logging
|
||||
import pilkit.processors
|
||||
import sys
|
||||
|
||||
from PIL import Image as PILImage
|
||||
from PIL import ImageDraw, ImageOps
|
||||
from pilkit.processors import ProcessorPipeline, Transpose, ResizeToFill
|
||||
from pilkit.processors import Transpose
|
||||
from pilkit.utils import save_image
|
||||
|
||||
|
||||
def generate_image(source, outname, size, format, options=None,
|
||||
autoconvert=True, copyright_text=''):
|
||||
autoconvert=True, copyright_text='', method='ResizeToFit'):
|
||||
"""Image processor, rotate and resize the image.
|
||||
|
||||
:param source: path to an image
|
||||
@@ -42,14 +45,20 @@ def generate_image(source, outname, size, format, options=None,
|
||||
|
||||
# Rotate the img, and catch IOError when PIL fails to read EXIF
|
||||
try:
|
||||
processor = Transpose()
|
||||
img = processor.process(img)
|
||||
img = Transpose().process(img)
|
||||
except IOError:
|
||||
pass
|
||||
|
||||
# Run the other processors
|
||||
processors = [ResizeToFill(*size, upscale=False)]
|
||||
img = ProcessorPipeline(processors).process(img)
|
||||
# Resize the image
|
||||
try:
|
||||
logger.debug('Processor: %s', method)
|
||||
processor_cls = getattr(pilkit.processors, method)
|
||||
except AttributeError as e:
|
||||
logger.error('Wrong processor name: %s', method)
|
||||
sys.exit()
|
||||
|
||||
processor = processor_cls(*size, upscale=False)
|
||||
img = processor.process(img)
|
||||
|
||||
if copyright_text:
|
||||
add_copyright(img, copyright_text)
|
||||
|
||||
@@ -27,6 +27,7 @@ _DEFAULT_CONFIG = {
|
||||
'source': '',
|
||||
'destination': '_build',
|
||||
'img_size': (640, 480),
|
||||
'img_processor': 'ResizeToFit',
|
||||
'make_thumbs': True,
|
||||
'thumb_prefix': '',
|
||||
'thumb_suffix': '',
|
||||
|
||||
@@ -19,6 +19,13 @@ theme = 'galleria'
|
||||
# Size of resized image
|
||||
img_size = (800, 600)
|
||||
|
||||
# Pilkit processor used to resize the image
|
||||
# (see http://pilkit.readthedocs.org/en/latest/#processors)
|
||||
# - ResizeToFit: fit the image within the specified dimensions (default)
|
||||
# - ResizeToFill: crop THE IMAGE it to the exact specified width and height
|
||||
# - SmartResize: identical to ResizeToFill, but uses entropy to crop the image
|
||||
# img_processor = 'ResizeToFit'
|
||||
|
||||
# Generate thumbnails
|
||||
# make_thumbs = True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user