def process_thumbnailer_options(kwargs): default_options = getattr(settings, "THUMBNAIL_DEFAULT_OPTIONS", {}) options = {} options.update(default_options) options.update(kwargs) size = options.setdefault('size', (128, 128)) if isinstance(size, six.text_type): m = RE_SIZE.match(size) if m: options["size"] = (int(m.group(1)), int(m.group(2))) else: raise ValueError("%r is not a valid size." % size) return options
def process_thumbnailer_options(kwargs): default_options = getattr(settings, "THUMBNAIL_DEFAULT_OPTIONS", {}) options = {} options.update(default_options) options.update(kwargs) size = options.setdefault('size', (128, 128)) if isinstance(size, six.text_type): m = RE_SIZE.match(size) if m: options["size"] = (int(m.group(1)), int(m.group(2))) else: raise ValueError("%r is not a valid size." % size) return options
def thumbnail_obj(source, size, **opts): """Make thumbnail from source image""" if not source: return None raise_errors = thumbnailer_settings.THUMBNAIL_DEBUG accepted_opts = {} for key, value in opts.items(): if key in VALID_OPTIONS: accepted_opts[key] = value opts = accepted_opts m = RE_SIZE.match(size) if m: opts['size'] = (int(m.group(1)), int(m.group(2))) else: if raise_errors: raise TemplateSyntaxError('%r is not a valid size.' % size, 1) if 'quality' in opts: try: opts['quality'] = int(opts['quality']) except (TypeError, ValueError): if raise_errors: raise TemplateSyntaxError( '%r is an invalid quality.' % opts['quality'], 1) try: curr_thumbnail = get_thumbnailer(source).get_thumbnail(opts) except Exception as e: if raise_errors: raise TemplateSyntaxError( 'Couldn\'t get the thumbnail %s: %s' % (source, e), 1) else: return None return curr_thumbnail