def watermark(self, image, options): """ Wrapper for ``_watermark`` Takes care of all the options handling. """ watermark_img = options.get('watermark', settings.THUMBNAIL_WATERMARK) if not watermark_img: raise AttributeError('Trying to apply a watermark, ' 'however no THUMBNAIL_WATERMARK defined, ' 'and watermark not set on tag') watermark_path = find(watermark_img) if not 'cropbox' in options: options['cropbox'] = None if not 'watermark_alpha' in options: options['watermark_alpha'] = settings.THUMBNAIL_WATERMARK_OPACITY mark_sizes = options.get('watermark_size', settings.THUMBNAIL_WATERMARK_SIZE) if mark_sizes: try: options['watermark_size'] = parse_geometry( mark_sizes, self.get_image_ratio(image, options)) except TypeError, e: raise TypeError('Please, update sorl-thumbnail package version to >= 11.12b. %s' % e)
def watermark(self, image, options): """ Wrapper for ``_watermark`` Takes care of all the options handling. """ if not THUMBNAIL_WATERMARK: raise AttributeError('Trying to apply a watermark, ' 'however no THUMBNAIL_WATERMARK defined') watermark_path = os.path.join(STATIC_ROOT, THUMBNAIL_WATERMARK) if not 'watermark_alpha' in options: options['watermark_alpha'] = THUMBNAIL_WATERMARK_OPACITY if not 'watermark_size' in options and THUMBNAIL_WATERMARK_SIZE: options['watermark_size'] = THUMBNAIL_WATERMARK_SIZE elif 'watermark_size' in options: options['watermark_size'] = parse_geometry( options['watermark_size'], self.get_image_ratio(image), ) else: options['watermark_size'] = False return self._watermark(image, watermark_path, options['watermark_alpha'], options['watermark_size'])
def watermark(self, image, options): """ Wrapper for ``_watermark`` Takes care of all the options handling. """ watermark_img = options.get('watermark', settings.THUMBNAIL_WATERMARK) if not watermark_img: raise AttributeError('Trying to apply a watermark, ' 'however no THUMBNAIL_WATERMARK defined, ' 'and watermark not set on tag') watermark_path = find(watermark_img) if not 'watermark_alpha' in options: options['watermark_alpha'] = settings.THUMBNAIL_WATERMARK_OPACITY if 'watermark_size' in options or settings.THUMBNAIL_WATERMARK_SIZE: mark_sizes = options.get('watermark_size', settings.THUMBNAIL_WATERMARK_SIZE) options['watermark_size'] = parse_geometry( mark_sizes, self.get_image_ratio(image)) else: options['watermark_size'] = False if not 'watermark_pos' in options: options['watermark_pos'] = settings.THUMBNAIL_WATERMARK_POSITION return self._watermark(image, watermark_path, options['watermark_alpha'], options['watermark_size'], options['watermark_pos'])
def watermark(self, image, options): """ Wrapper for ``_watermark`` Takes care of all the options handling. """ watermark_img = options.get('watermark', settings.THUMBNAIL_WATERMARK) if not watermark_img: raise AttributeError('Trying to apply a watermark, ' 'however no THUMBNAIL_WATERMARK defined, ' 'and watermark not set on tag') watermark_path = find(watermark_img) if not 'cropbox' in options: options['cropbox'] = None if not 'watermark_alpha' in options: options['watermark_alpha'] = settings.THUMBNAIL_WATERMARK_OPACITY mark_sizes = options.get('watermark_size', settings.THUMBNAIL_WATERMARK_SIZE) if mark_sizes: try: options['watermark_size'] = parse_geometry( mark_sizes, self.get_image_ratio(image, options)) except TypeError, e: raise TypeError( 'Please, update sorl-thumbnail package version to >= 11.12b. %s' % e)
def watermark(self, image, options): """ Wrapper for ``_watermark`` Takes care of all the options handling. """ if not 'watermark' in options: watermark_path = os.path.join(STATIC_ROOT, THUMBNAIL_WATERMARK) else: watermark_path = os.path.join(STATIC_ROOT, options['watermark']) if not 'watermark_alpha' in options: options['watermark_alpha'] = THUMBNAIL_WATERMARK_OPACITY if not 'watermark_size' in options and THUMBNAIL_WATERMARK_SIZE: options['watermark_size'] = THUMBNAIL_WATERMARK_SIZE elif 'watermark_size' in options: options['watermark_size'] = parse_geometry( options['watermark_size'], self.get_image_ratio(image), ) else: options['watermark_size'] = False return self._watermark(image, watermark_path, options['watermark_alpha'], options['watermark_size'], options['watermark_pos'])
def watermark(self, image, options): """ Wrapper for ``_watermark`` Takes care of all the options handling. """ watermark_img = options.get('watermark', settings.THUMBNAIL_WATERMARK) if not watermark_img: raise AttributeError('Trying to apply a watermark, ' 'however no THUMBNAIL_WATERMARK defined, ' 'and watermark not set on tag') # Note - I do not think find can be used for this purpose - it is used for collecting static files to the static folder # Use os.path.join with the static root instead, and if not found, raise the error. watermark_path = find(watermark_img) if not watermark_path: watermark_path = os.path.join(settings.STATIC_ROOT, watermark_img) if not os.path.isfile(watermark_path): raise AttributeError('Trying to apply a watermark, ' 'however no THUMBNAIL_WATERMARK defined, ' 'or watermark can not be found!') if not 'cropbox' in options: options['cropbox'] = None if not 'watermark_alpha' in options: options['watermark_alpha'] = settings.THUMBNAIL_WATERMARK_OPACITY mark_sizes = options.get('watermark_size', settings.THUMBNAIL_WATERMARK_SIZE) if mark_sizes: try: options['watermark_size'] = parse_geometry( mark_sizes, self.get_image_ratio(image, options)) except TypeError as e: raise TypeError('Please, update sorl-thumbnail package version to >= 11.12b. %s' % e) else: options['watermark_size'] = False if not 'watermark_pos' in options: options['watermark_pos'] = settings.THUMBNAIL_WATERMARK_POSITION return self._watermark(image, watermark_path, options['watermark_alpha'], options['watermark_size'], options['watermark_pos'])
def watermark(self, image, options): """ Wrapper for ``_watermark`` Takes care of all the options handling. """ watermark_img = options.get("watermark", settings.THUMBNAIL_WATERMARK) if not watermark_img: raise AttributeError( "Trying to apply a watermark, " "however no THUMBNAIL_WATERMARK defined, " "and watermark not set on tag" ) watermark_path = find(watermark_img) if not "cropbox" in options: options["cropbox"] = None if not "watermark_alpha" in options: options["watermark_alpha"] = settings.THUMBNAIL_WATERMARK_OPACITY mark_sizes = options.get("watermark_size", settings.THUMBNAIL_WATERMARK_SIZE) if mark_sizes: try: options["watermark_size"] = parse_geometry(mark_sizes, self.get_image_ratio(image, options)) except TypeError as e: raise TypeError("Please, update sorl-thumbnail package version to >= 11.12b. %s" % e) else: options["watermark_size"] = False if not "watermark_pos" in options: options["watermark_pos"] = settings.THUMBNAIL_WATERMARK_POSITION return self._watermark( image, watermark_path, options["watermark_alpha"], options["watermark_size"], options["watermark_pos"] )