diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:24:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:24:48 +0000 |
commit | cca66b9ec4e494c1d919bff0f71a820d8afab1fa (patch) | |
tree | 146f39ded1c938019e1ed42d30923c2ac9e86789 /share/extensions/color_replace.py | |
parent | Initial commit. (diff) | |
download | inkscape-12fc8abae6d434cac7670a59ed3a67301cc2eb10.tar.xz inkscape-12fc8abae6d434cac7670a59ed3a67301cc2eb10.zip |
Adding upstream version 1.2.2.upstream/1.2.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rwxr-xr-x | share/extensions/color_replace.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/share/extensions/color_replace.py b/share/extensions/color_replace.py new file mode 100755 index 0000000..a4be3d5 --- /dev/null +++ b/share/extensions/color_replace.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python +"""Replace color extension""" + +import inkex + + +class ReplaceColor(inkex.ColorExtension): + """Replace color in SVG with another""" + + pass_rgba = True + + def add_arguments(self, pars): + pars.add_argument("--tab") + pars.add_argument( + "-f", + "--from_color", + default=inkex.Color("black"), + type=inkex.Color, + help="Replace color", + ) + pars.add_argument( + "-t", + "--to_color", + default=inkex.Color("red"), + type=inkex.Color, + help="By color", + ) + pars.add_argument( + "-i", + "--ignore_opacity", + default=True, + type=inkex.Boolean, + help="Whether color should be replaced regardless of opacity match", + ) + + def modify_color(self, name, color): # color is rgba + if self.options.from_color.to_rgb() == color.to_rgb() and ( + self.options.ignore_opacity + or abs(self.options.from_color.to_rgba().alpha - color.alpha) < 0.01 + ): + return self.options.to_color.to_rgba() + return color + + +if __name__ == "__main__": + ReplaceColor().run() |