def fit(image, width, height, mode, upscale, filter, blur): # @ReservedAssignment width_, height_ = _proportionally(image, width, height) smaller = image.width <= width_ and image.height <= height_ if (smaller and upscale) or not smaller: if not width or not height: return rescale(image, width, height, None, filter, blur) background = blank(width, height) if not mode: mode = 'in' if not smaller or upscale: width, height = _calculate_mode(image, width, height, mode) rescale(image, width, height, None, filter, blur) x, y = ((background.width - image.width) / 2, (background.height - image.height) / 2) background.overlay(image, x, y) image._replace(background)
def write( image, filename, format, # @ReservedAssignment compression, quality, flatten, background): if not format: format = splitext(filename)[1][1:].lower() # @ReservedAssignment if flatten is None: flatten = (image.type.name.endswith('matte') and format not in ('png', 'tiff', 'tif', 'bmp', 'gif')) if not background: background = 'white' if flatten: background = blank(image.width, image.height, background) background.overlay(image) image = background with state(image, format=format, compression_quality=quality): c_call(image, 'write', filename)
def set_color(image, fill): if get_c_method('image', ('set', 'color'), throw=False): c_call(image, ('set', 'color'), fill) # MagickSetImageColor doesnt copy alpha if not fill.opaque: set_alpha(image, fill.alpha) else: width, height = image.size image._free() image.__init__(blank(width, height, fill)._claim())
def colorize(self, color): """Colorize image. :param color: color from which hue value is used :type color: :class:`pystacia.color.Color` Colorizes image resulting in image containing only one hue value. This method can be chained. """ overlay = blank(self.width, self.height, color) self.overlay(overlay, composite=composites.colorize) overlay.close()
def write(image, filename, format, # @ReservedAssignment compression, quality, flatten, background): if not format: format = splitext(filename)[1][1:].lower() # @ReservedAssignment if flatten is None: flatten = (image.type.name.endswith('matte') and format not in ('png', 'tiff', 'tif', 'bmp', 'gif')) if not background: background = 'white' if flatten: background = blank(image.width, image.height, background) background.overlay(image) image = background with state(image, format=format, compression_quality=quality): c_call(image, 'write', filename)