def __init__( self, image_store, source_image_relative_url, dimensions=None, format=None, quality=80, fill=False, bgcolor=None, upscale=True, progressive=True, name_hashing_method=constants.DEFAULT_NAME_HASHING_METHOD, cache_store=cache.NoopCache(), target_directory=constants.DEFAULT_TARGET_DIRECTORY, use_placeholder=False, ): self.source_image_relative_url = source_image_relative_url self.use_placeholder = use_placeholder self.width, self.height = (utils.parse_dimensions(dimensions) if dimensions is not None else (None, None)) self.format = utils.parse_format(source_image_relative_url, format) self.quality = quality self.fill = fill self.bgcolor = (utils.parse_rgb(bgcolor, include_number_sign=False) if bgcolor is not None else None) self.upscale = upscale self.progressive = progressive self.name_hashing_method = name_hashing_method self.target_directory = target_directory self.image_store = image_store self.cache_store = cache_store self._validate_arguments() self.unique_key = self._generate_unique_key()
def make_opaque(img, bgcolor): """Apply a background color to image Args: img (PIL.Image): Image to alter. bgcolor (str): A :func:`parse_rgb` parseable value to use as background color. Returns: PIL.Image: A new image with the background color applied. """ bgcolor = ImageColor.getrgb(utils.parse_rgb(bgcolor)) processor = pilkit.processors.MakeOpaque(background_color=bgcolor) return processor.process(img)
def __init__( self, image_store, source_image_relative_url, dimensions=None, format=None, quality=80, fill=False, bgcolor=None, upscale=True, progressive=True, name_hashing_method=constants.DEFAULT_NAME_HASHING_METHOD, cache_store=cache.NoopCache(), target_directory=constants.DEFAULT_TARGET_DIRECTORY, use_placeholder=False, ): self.source_image_relative_url = source_image_relative_url self.use_placeholder = use_placeholder self.width, self.height = ( utils.parse_dimensions(dimensions) if dimensions is not None else (None, None) ) self.format = utils.parse_format(source_image_relative_url, format) self.quality = quality self.fill = fill self.bgcolor = ( utils.parse_rgb(bgcolor, include_number_sign=False) if bgcolor is not None else None ) self.upscale = upscale self.progressive = progressive self.name_hashing_method = name_hashing_method self.target_directory = target_directory self.image_store = image_store self.cache_store = cache_store self._validate_arguments() self.unique_key = self._generate_unique_key()