def filter_function(red=None, green=None, blue=None, alpha=None, hue=None, saturation=None, lightness=None, L=None, a=None, b=None, corrected_hue=None, gamma_correction=None, validate=True): #expressions: str command.send("Filter", Name=FILTER_FUNCTION, Red=red, Green=green, Blue=blue, Alpha=alpha, Hue=hue, Saturation=saturation, Lightness=lightness, CorrectedHue=corrected_hue, GammaCorrection=gamma_correction, Validate=validate)
def emboss(angle=None, transparent=None, preserve_colors=None, validate=True): command.send("Filter", Name=EMBOSS, Angle=angle, Transparent=transparent, PreserveColors=preserve_colors, Validate=validate)
def lightness(factor=None, shift=None, validate=True): #factor and shift: -2..2 command.send('ColorLightness', Factor=factor, Shift=shift, Validate=validate)
def intensity(factor=None, shift=None, validate=True): #factor and shift: -2..2 command.send('ColorIntensity', Factor=factor, Shift=shift, Validate=validate)
def noise(grayscale=None, opacity=None, validate=True): #grayscale: bool, opacity: 0..255 command.send("Filter", Name=NOISE, Grayscale=grayscale, Opacity=opacity, Validate=validate)
def shift(hue_angle=None, saturation=None, correction=None, validate=True): #saturation shift: -2..2 command.send('ColorShiftColors', Hue=hue_angle, Saturation=saturation, Correction=correction, Validate=validate)
def colorize(hue_angle=None, saturation=None, correction=None, validate=True): #saturation: 0..1 command.send('ColorColorize', Hue=hue_angle, Saturation=saturation, Correction=correction, Validate=validate)
def blur_motion(distance=None, angle=None, oriented=None, validate=True): #oriented: bool command.send("Filter", Name=BLUR_MOTION, Distance=distance, Angle=angle, Oriented=oriented, Validate=validate)
def mouse(coords, state=[STATE_LEFT], default_pressure=1.0): if not isinstance(coords, list): xy = [(float(coords[0]), float(coords[1]))] if len(coords) > 2: pressure = [float(coords[2])] else: pressure = [default_pressure] else: xy = [(float(c[0]), float(c[1])) for c in coords] pressure = [ float(c[2]) if len(c) > 2 else default_pressure for c in coords ] command.send("ToolMouse", Coords=xy, State=state, Pressure=pressure)
def blur(name=BLUR_FAST, radius=None, validate=True): #radius: float or (x,y) if isinstance(radius, tuple): radius_x = radius[0] radius_y = radius[1] radius = None else: radius_x = None radius_y = None command.send("Filter", Name=name, Radius=radius, RadiusX=radius_x, RadiusY=radius_y, Validate=validate)
def twirl(radius=None, angle=None, center_pos_percent=None, center_x_percent=None, center_y_percent=None, validate=True): command.send("Filter", Name=TWIRL, Radius=radius, Angle=angle, CenterPosPercent=center_pos_percent, CenterXPercent=center_x_percent, CenterYPercent=center_y_percent, Validate=validate)
def put_image(x: int, y: int, image, mode=DM_DRAW, opacity=255): width, height = get_image_size(image) if width == 0 or height == 0: return flattened = "" for scanline in image: flattened += "".join([str(color) for color in scanline ]) + "00000000" * (width - len(scanline)) command.send("PutImage", X=x, Y=y, Width=width, Height=height, Data=flattened, Mode=mode, Opacity=opacity)
def wave_displacement(wave_length=None, displacement=None, phase=None, center_pos_percent=None, center_x_percent=None, center_y_percent=None, validate=True): #phase: 0..360 command.send("Filter", Name=WAVE_DISPLACEMENT, WaveLength=wave_length, Displacement=displacement, Phase=phase, CenterPosPercent=center_pos_percent, CenterXPercent=center_x_percent, CenterYPercent=center_y_percent, Validate=validate)
def phong(color_source=None, altitude_percent=None, altitude_source=None, light_pos_percent=None, light_x_percent=None, light_y_percent=None, validate=True): command.send("Filter", Name=PHONG, ColorSource=color_source, AltitudePercent=altitude_percent, AltitudeSource=altitude_source, LightPosPercent=light_pos_percent, LightXPercent=light_x_percent, LightYPercent=light_y_percent, Validate=validate)
def curves(red=[], red_posterize=False, green=[], green_posterize=False, blue=[], blue_posterize=False, hue=[], hue_posterize=False, saturation=[], saturation_posterize=False, lightness=[], lightness_posterize=False, validate=True): command.send('ColorCurves', Red=get_curve(red, red_posterize), Green=get_curve(green, green_posterize), Blue=get_curve(blue, blue_posterize), Hue=get_curve(hue, hue_posterize), Saturation=get_curve(saturation, saturation_posterize), Lightness=get_curve(lightness, lightness_posterize), Validate=validate)
def get_image(x: int, y: int, width: int, height: int): flattened = command.send("GetImage?", X=x, Y=y, Width=width, Height=height) str_pos = 0 image = [] for yb in range(0, height): scanline = [] for xb in range(0, width): scanline.append( colors.RGBA(int(flattened[str_pos:str_pos + 2], 16), int(flattened[str_pos + 2:str_pos + 4], 16), int(flattened[str_pos + 4:str_pos + 6], 16), int(flattened[str_pos + 6:str_pos + 8], 16))) str_pos = str_pos + 8 image.append(scanline) return image
def new(name: str = None): #-> id layer_id = command.send("LayerAddNew?") if name is not None: set_name(name) return layer_id
def set_blend_op(blend_op): return command.send("LayerSetBlendOp", BlendOp=blend_op)
def set_visible(visible: bool): return command.send("LayerSetVisible", Visible=visible)
def set_name(name: str): return command.send("LayerSetName", Name=str(name))
def set_opacity(opacity: int): return command.send("LayerSetOpacity", Opacity=opacity)
def get_visible() -> bool: return command.send("LayerGetVisible?")
def select_id(id): command.send("LayerSelectId", Id=id)
def get_opacity() -> int: return command.send("LayerGetOpacity?")
def get_blend_op(): return command.send("LayerGetBlendOp?")
def get_name() -> str: return command.send("LayerGetName?")
def get_id(): return command.send("LayerGetId?")
def fill_background(back_color=None): command.send("ImageFillBackground", BackColor=back_color)
def clear_alpha(back_color=None): command.send("ImageClearAlpha", BackColor=back_color)
def vertical_flip(): command.send("LayerVerticalFlip")