From: Joar Wandborg Date: Tue, 22 Jan 2013 16:55:55 +0000 (+0100) Subject: Made the image sampling filter configurable X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=7cd7db5af402f9ff9160d80da2852c9e6db60859;p=mediagoblin.git Made the image sampling filter configurable - Changed the default to BICUBIC instead of previous ANTIALIAS --- diff --git a/mediagoblin/config_spec.ini b/mediagoblin/config_spec.ini index bee67d46..ca06cc0a 100644 --- a/mediagoblin/config_spec.ini +++ b/mediagoblin/config_spec.ini @@ -86,6 +86,10 @@ max_height = integer(default=640) max_width = integer(default=180) max_height = integer(default=180) +[media_type:mediagoblin.media_types.image] +# One of BICUBIC, BILINEAR +resize_filter = string(default="BICUBIC") + [media_type:mediagoblin.media_types.video] # Should we keep the original file? keep_original = boolean(default=False) diff --git a/mediagoblin/media_types/image/processing.py b/mediagoblin/media_types/image/processing.py index e6a34ca0..f5fb9a72 100644 --- a/mediagoblin/media_types/image/processing.py +++ b/mediagoblin/media_types/image/processing.py @@ -47,7 +47,25 @@ def resize_image(entry, filename, new_path, exif_tags, workdir, new_size, except IOError: raise BadMediaFail() resized = exif_fix_image_orientation(resized, exif_tags) # Fix orientation - resized.thumbnail(new_size, Image.ANTIALIAS) + + pil_filters = { + 'NEAREST': Image.NEAREST, + 'BILINEAR': Image.BILINEAR, + 'BICUBIC': Image.BICUBIC, + 'ANTIALIAS': Image.ANTIALIAS} + + filter_config = \ + mgg.global_config['media_type:mediagoblin.media_types.image']\ + ['resize_filter'] + + try: + resize_filter = pil_filters[filter_config.upper()] + except KeyError: + raise Exception('Filter "{0}" not found, choose one of {1}'.format( + unicode(filter_config), + u', '.join(pil_filters.keys()))) + + resized.thumbnail(new_size, resize_filter) # Copy the new file to the conversion subdir, then remotely. tmp_resized_filename = os.path.join(workdir, new_path[-1])