"Supprimer ce calque pour enlever la teinte", "This is not a chromatic channel": "Ce n'est pas un canal chromatique" }, es={ "Remove this layer to remove hue": "Elimina esta capa para eliminar el tono", "This is not a chromatic channel": "Este no es un canal cromático" }, de={ "Remove this layer to remove hue": "Diese Ebene entfernen, um den Farbton zu entfernen", "This is not a chromatic channel": "Dies ist kein chromatischer Kanal" }, ) channel = layer.get_registry("split-channel") if channel == "R" or channel == "C": source = "red" elif channel == "G" or channel == "M": source = "green" elif channel == "B" or channel == "Y": source = "blue" elif channel == "H": dialog.show_message(translation["Remove this layer to remove hue"]) exit() else: dialog.show_message(translation["This is not a chromatic channel"]) exit() filters.filter_function(red=source, green=source, blue=source)
# Layer effect > Inner shadow from lazpaint import dialog try: from tkinter import * except ImportError: dialog.show_message("Please install tkinter.") exit() from lazpaint import colors, image, layer, filters, tools, selection import math if layer.is_empty(): dialog.show_message("Layer is empty") exit() ############ image processing FRIENDLY_NAME = "Inner shadow" REGISTRY_NAME = "innershadow" OPPOSITE_REGISTRY_NAME = "innerlight" DEFAULT_ANGLE = 135 DEFAULT_COLOR = colors.BLACK MAX_RADIUS = 200 MAX_OPACITY = 255 MAX_ANGLE = 360 source_layer_id = layer.get_registry(REGISTRY_NAME + "-source-layer-id") if source_layer_id is not None: layer.select_id(source_layer_id)
# Merge RGB channels from lazpaint import image, dialog, layer try: from PIL import Image except ImportError: dialog.show_message("Please install Pillow for Python.") exit() channels_id = None image.do_begin() if layer.get_registry("split-channel") is not None: layer_id = layer.get_registry("split-source-id") if image.contains_layer_id(layer_id): layer.select_id(layer_id) channels_id = layer.get_registry("split-channels-id") else: channels_id = [] for i in range(1, image.get_layer_count() + 1): image.select_layer_index(i) cur_layer_id = layer.get_registry("split-source-id") if cur_layer_id == layer_id: channels_id.append(layer.get_id()) else: layer_id = layer.get_id() channels_id = layer.get_registry("split-channels-id") if channels_id is None: dialog.show_message("Current layer is not split") exit()
from lazpaint import command, dialog, colors, layer import os if __name__ == "__main__": dialog.show_message("Library to act on the whole image.") RESAMPLE_QUALITY_BOX = 'Box' RESAMPLE_QUALITY_LINEAR = 'Linear' RESAMPLE_QUALITY_HALF_COSINE = 'HalfCosine' RESAMPLE_QUALITY_COSINE = 'Cosine' RESAMPLE_QUALITY_BICUBIC = 'Bicubic' RESAMPLE_QUALITY_MITCHELL = 'Mitchell' RESAMPLE_QUALITY_SPLINE = 'Spline' RESAMPLE_QUALITY_LANCZOS2 = 'Lanczos2' RESAMPLE_QUALITY_LANCZOS3 = 'Lanczos3' RESAMPLE_QUALITY_LANCZOS4 = 'Lanczos4' RESAMPLE_QUALITY_BEST = 'BestQuality' ANCHOR_TOP_LEFT = 'TopLeft' ANCHOR_TOP = 'Top' ANCHOR_TOP_RIGHT = 'TopRight' ANCHOR_LEFT = 'Left' ANCHOR_MIDDLE = 'Middle' ANCHOR_RIGHT = 'Right' ANCHOR_BOTTOM_LEFT = 'BottomLeft' ANCHOR_BOTTOM = 'Bottom' ANCHOR_BOTTOM_RIGHT = 'BottomRight' def new(width: int, height: int, color=colors.TRANSPARENT, ignore_modified=False): command.send("FileNew", Width=width, Height=height, BackColor=color, IgnoreModified=ignore_modified)
from lazpaint import command, dialog import glob if __name__ == "__main__": dialog.show_message("Library to act on the image list.") UNCHECK_OFF = 'UncheckOff' UNCHECK_ON_OPEN = 'UncheckOnOpen' UNCHECK_ON_SAVE = 'UncheckOnSave' def get_file_count() -> int: return command.send("ImageListGetFileCount?") def get_selected_index() -> int: return command.send("ImageListGetSelectedIndex?") def set_selected_index(index: int): command.send("ImageListSetSelectedIndex", Index=index) def add_files(file_names: list) -> int: if isinstance(file_names, str): file_names = glob.glob(file_names) return command.send("ImageListAddFiles?", FileNames=file_names) def index_of_file(file_name: str) -> int: return command.send("ImageListIndexOfFileName?", FileName=file_name)
"Black": "Negro", "Alpha": "Alpha" }, de={ "Layer already split": "Die Ebene ist bereits geteilt", "Cyan": "Cyan", "Magenta": "Magenta", "Yellow": "Gelb", "Black": "Schwartz", "Alpha": "Alpha" }) # check if it is a channel if layer.get_registry("split-channel") is not None: dialog.show_message(translation["Layer already split"]) exit() layer_id = layer.get_id() layer_index = image.get_layer_index() layer_opacity = layer.get_opacity() layer_transparent = layer.is_transparent() cmy_id = None black_id = None # check if it has been split if layer.get_registry("split-channels-id") is not None: for cur_layer_id in image.iterate_layers(): if layer.get_registry("split-source-id") == layer_id: dialog.show_message(translation["Layer already split"]) exit()
# Layer effect > Drop shadow # (fr) Effet de calque > Ombre portée # (es) Efectos de capa > Sombra paralela # (de) Ebeneneffekte > Schlagschatten from lazpaint import dialog try: from tkinter import * except ImportError: dialog.show_message( "Please install tkinter. On Debian distributions, use the command: apt install python3-tk" ) exit() from lazpaint import colors, image, layer, filters, tools, selection english = [ "Layer is empty", "Shadow of ", "Radius", "Offset", "Opacity", "Ok", "Cancel" ] translation = dict(zip(english, dialog.translate_text(english))) if layer.is_empty(): dialog.show_message(translation["Layer is empty"]) exit() ############ image processing FRIENDLY_NAME = dialog.get_script_name() MAX_RADIUS = 100 MAX_OFFSET = 100
import collections, math from lazpaint import dialog, command, filters GAMMA = 2.2 ALPHA_OPAQUE = 255 ALPHA_TRANSPARENT = 0 if __name__ == "__main__": dialog.show_message("Library defining colors.") def to_linear(std_value: int): #0..255 return math.pow(std_value / 255, GAMMA) def to_std(linear_value: float): return round(math.pow(linear_value, 1 / GAMMA) * 255) CustomRGBA = collections.namedtuple("RGBA", "red, green, blue, alpha") class RGBA(CustomRGBA): def __repr__(self): if self.alpha != 255: return '#{:02X}{:02X}{:02X}{:02X}'.format(self.red, self.green, self.blue, self.alpha) else: return '#{:02X}{:02X}{:02X}'.format(self.red, self.green, self.blue)
# Split RGB channels (using Pillow) from lazpaint import image, dialog, layer try: from PIL import Image except ImportError: dialog.show_message("Please install Pillow for Python.") exit() # check if it is a channel if layer.get_registry("split-channel") is not None: dialog.show_message("Layer already split") exit() layer_id = layer.get_id() layer_index = image.get_layer_index() layer_opacity = layer.get_opacity() layer_transparent = layer.is_transparent() # check if it has been split if layer.get_registry("split-channels-id") is not None: for i in range(1, layer.get_count()): image.select_layer_index(i) if layer.get_registry("split-source-id") == layer_id: dialog.show_message("Layer already split") exit() layer.select_id(layer_id) temp_name = image.get_temporary_name() temp_name = layer.save_as(temp_name) if temp_name is None:
from lazpaint import image, colors, layer, selection, dialog current_file_name = image.get_name() if current_file_name is not None: dialog.show_message("Filename is \"" + current_file_name + "\"") else: dialog.show_message("Image doesn't have a filename") if selection.is_mask_empty(): selection_name = None dialog.show_message("There is no selection mask") else: selection_name = selection.save_as("script_test_selection.png") dialog.show_message("Selection saved") image.new(100, 100, colors.RED) if selection_name is not None: selection.load(selection_name) dialog.show_message("Selection restored") wanted_file_name = dialog.input_text("Test file name:", "script_test_file.png") file_name = image.save_as(wanted_file_name, skip_options=True) image.new(100, 100, colors.LIME) image.save_as(file_name, validate=True, overwrite=True, skip_options=True) layer.fill(colors.BLUE) image.reload(ignore_modified=True) layer.fill(colors.PURPLE) image.save(skip_options=True)
from lazpaint import image, layer, colors, view, dialog dialog.show_message(image.get_size()) w = 256 h = 256 image.new(2, 2) layer.put_image(0, 0, [[colors.RGB(128,128,255), colors.RGB(0,255,255)], [colors.RGB(255,0,255), colors.RGB(255,255,255)]], layer.DM_SET) image.resample(w, h) image.repeat(w*4, h*4, anchor=image.ANCHOR_TOP_LEFT) view.zoom_fit() pix1 = layer.get_pixel(0,0) image.horizontal_flip() assert layer.get_pixel(w-1,0) == pix1 image.vertical_flip() assert layer.get_pixel(w-1,h-1) == pix1 image.rotate_cw() assert layer.get_pixel(0,h-1) == pix1 image.rotate_cw() assert layer.get_pixel(0,0) == pix1 image.linear_negative() pix1 = pix1.linear_negative() assert layer.get_pixel(0,0) == pix1 pix1 = pix1.swap_red_blue() image.swap_red_blue() assert layer.get_pixel(0,0) == pix1 layer.new() layer.fill(colors.RGBA(192,192,192,64)) image.flatten()
line_buf.append( (x2, y2) ) else: flush_line() line_buf = [(x, y), (x2, y2)] def flush_line(): global line_buf if len(line_buf) > 0: tools.choose(tools.PEN) tools.mouse(line_buf) line_buf = [] DEG_TO_RAD = math.pi / 180 ANGLE = abs(dialog.input_value(dialog.translate_text("Angle") + " (< 90)", 45)) if ANGLE >= 90: dialog.show_message(translation["Invalid angle"]) exit() DEFAULT_SIZE_Y = 7*8/2*2 * (1.14+math.cos(ANGLE * DEG_TO_RAD))/2.14 MULTIPLIER = image.get_height() / DEFAULT_SIZE_Y ZOOM = dialog.input_value(translation["Vertical size"] + " (%)", 95) MULTIPLIER = MULTIPLIER * ZOOM/100 def drawTree(x1, y1, angle, depth): if (depth > 0): x2 = x1 + (math.cos(angle * DEG_TO_RAD) * depth * MULTIPLIER) y2 = y1 + (math.sin(angle * DEG_TO_RAD) * depth * MULTIPLIER) line(x1, y1, x2, y2) drawTree(x2, y2, angle - ANGLE, depth - 2) drawTree(x2, y2, angle + ANGLE, depth - 2)
from lazpaint import image, layer, dialog, colors, view view.set_zoom(1) width = 256 height = 256 image.new(width, height) red = dialog.input_value("Red value (0..255)", 0) image = [] for y in range(height): scanline = [colors.RGB(red, x, y) for x in range(width)] image.append(scanline) layer.put_image(0, 0, image, layer.DM_SET) if layer.get_pixel(192, 64).green != 192: dialog.show_message("The value of the pixel is not correct.") else: dialog.show_message("Test successful.") view.zoom_fit() view.set_zoom(10) view.set_grid_visible(True)
new_layer_index = image.get_layer_index() + 1 else: channels_id = [] for cur_layer_id in image.iterate_layers(): cur_source_id = layer.get_registry("split-source-id") if cur_source_id == layer_id: channels_id.insert(0, cur_layer_id) if new_layer_index is None: new_layer_index = image.get_layer_index() else: layer_id = layer.get_id() channels_id = layer.get_registry("split-channels-id") new_layer_index = image.get_layer_index() + 1 if channels_id is None: dialog.show_message(translation["Current layer is not split"]) exit() layer.new(dialog.get_script_name()) image.move_layer_index(image.get_layer_index(), new_layer_index) for cur_layer_id in reversed(channels_id): layer.select_id(cur_layer_id) image.move_layer_index(image.get_layer_index(), new_layer_index + 1) layer.merge_over() new_layer_id = layer.get_id() if image.contains_layer_id(layer_id): layer.select_id(layer_id) layer_index = image.get_layer_index()
def show_frame(): dialog.show_message("Frame " + str(image.get_frame_index()) + '/' + str(image.get_frame_count()))
# Version # (fr) Version # (es) Versión # (de) Version from lazpaint import command, dialog import sys lazpaint_version = command.get_version() python_version = sys.version_info dialog.show_message("Python version " + str(python_version[0]) + "." + str(python_version[1]) + "." + str(python_version[2]) + ", " + "LazPaint version " + str(lazpaint_version[0]) + "." + str(lazpaint_version[1]) + "." + str(lazpaint_version[2]))
flush_line() line_buf = [(x, y), (x2, y2)] def flush_line(): global line_buf if len(line_buf) > 0: tools.choose(tools.PEN) tools.mouse(line_buf) line_buf = [] DEG_TO_RAD = math.pi / 180 ANGLE = abs(dialog.input_value("Angle (< 90)", 45)) if ANGLE >= 90: dialog.show_message("Invalid angle") DEFAULT_SIZE_Y = 7 * 8 / 2 * 2 * (1.14 + math.cos(ANGLE * DEG_TO_RAD)) / 2.14 MULTIPLIER = image.get_height() / DEFAULT_SIZE_Y ZOOM = dialog.input_value("Vertical size (%)", 95) MULTIPLIER = MULTIPLIER * ZOOM / 100 def drawTree(x1, y1, angle, depth): if (depth > 0): x2 = x1 + (math.cos(angle * DEG_TO_RAD) * depth * MULTIPLIER) y2 = y1 + (math.sin(angle * DEG_TO_RAD) * depth * MULTIPLIER) line(x1, y1, x2, y2) drawTree(x2, y2, angle - ANGLE, depth - 2) drawTree(x2, y2, angle + ANGLE, depth - 2)
from lazpaint import command, dialog if __name__ == "__main__": dialog.show_message("Library to execute filters on the current layer.") #filters BLUR_PRECISE = 'BlurPrecise' BLUR_RADIAL = 'BlurRadial' BLUR_FAST = 'BlurFast' BLUR_BOX = 'BlurBox' BLUR_CORONA = 'BlurCorona' BLUR_DISK = 'BlurDisk' BLUR_MOTION = 'BlurMotion' BLUR_CUSTOM = 'BlurCustom' PIXELATE = 'Pixelate' SHARPEN = 'Sharpen' SMOOTH = 'Smooth' MEDIAN = 'Median' NOISE = 'Noise' CLEAR_TYPE = 'ClearType' CLEAR_TYPE_INVERSE = 'ClearTypeInverse' FILTER_FUNCTION = 'Function' CONTOUR = 'Contour' EMBOSS = 'Emboss' PHONG = 'Phong' SPHERE = 'Sphere' TWIRL = 'Twirl' WAVE_DISPLACEMENT = 'WaveDisplacement' CYLINDER = 'Cylinder'
from lazpaint import command, dialog, colors if __name__ == "__main__": dialog.show_message("Library to access layer content.") DM_DRAW = "dmDrawWithTransparency" DM_LINEAR = "dmLinearBlend" DM_SET = "dmSet" DM_SET_EXCEPT_TRANSPARENT = "dmSetExceptTransparent" DM_XOR = "dmXor" BLEND_DRAW = 'Transparent' BLEND_LINEAR = 'LinearBlend' BLEND_LIGHTEN = 'Lighten' BLEND_SCREEN = 'Screen' BLEND_ADD = 'Additive' BLEND_LINEAR_ADD = 'LinearAdd' BLEND_COLOR_DODGE = 'ColorDodge' BLEND_DIVIDE = 'Divide' BLEND_NICE_GLOW = 'NiceGlow' BLEND_SOFT_LIGHT = 'SoftLight' BLEND_HARD_LIGHT = 'HardLight' BLEND_GLOW = 'Glow' BLEND_REFLECT = 'Reflect' BLEND_OVERLAY = 'Overlay' BLEND_DARK_OVERLAY = 'DarkOverlay' BLEND_DARKEN = 'Darken' BLEND_MULTIPLY = 'Multiply' BLEND_COLOR_BURN = 'ColorBurn' BLEND_DIFFERENCE = 'Difference' BLEND_LINEAR_DIFFERENCE = 'LinearDifference'
new_layer_index = image.get_layer_index() + 1 else: channels_id = [] for cur_layer_id in image.iterate_layers(): cur_source_id = layer.get_registry("split-source-id") if cur_source_id == layer_id: channels_id.insert(0, cur_layer_id) if new_layer_index is None: new_layer_index = image.get_layer_index() else: layer_id = layer.get_id() channels_id = layer.get_registry("split-channels-id") new_layer_index = image.get_layer_index() + 1 if channels_id is None: dialog.show_message("Current layer is not split") exit() layer.new("Merged channels") image.move_layer_index(image.get_layer_index(), new_layer_index) for cur_layer_id in reversed(channels_id): layer.select_id(cur_layer_id) image.move_layer_index(image.get_layer_index(), new_layer_index + 1) layer.merge_over() new_layer_id = layer.get_id() if image.contains_layer_id(layer_id): layer.select_id(layer_id) layer_index = image.get_layer_index()
# Channels > Split HSL from lazpaint import image, dialog, layer, filters # check if it is a channel if layer.get_registry("split-channel") is not None: dialog.show_message("Layer already split") exit() layer_id = layer.get_id() layer_index = image.get_layer_index() layer_opacity = layer.get_opacity() layer_transparent = layer.is_transparent() # check if it has been split if layer.get_registry("split-channels-id") is not None: for cur_layer_id in image.iterate_layers(): if layer.get_registry("split-source-id") == layer_id: dialog.show_message("Layer already split") exit() image.do_begin() channels = [] if layer_transparent: channels.append({ "name": "Alpha", "channel": "A", "hue": "0", "saturation": "0", "lightness": "alpha", "alpha": "255", "blend": layer.BLEND_MASK
from lazpaint import command, dialog if __name__ == "__main__": dialog.show_message("Library to access selection.") def load(file_name=None): command.send("FileLoadSelection", FileName=file_name) def save_as(file_name=None) -> str: return command.send("FileSaveSelectionAs?", FileName=file_name) def invert(): command.send("EditInvertSelection") def deselect(): command.send("EditDeselect") def copy(): command.send("EditCopy") def cut(): command.send("EditCut") def delete():