summaryrefslogtreecommitdiff
path: root/lib/extensions/png_realistic.py
diff options
context:
space:
mode:
authorKaalleen <36401965+kaalleen@users.noreply.github.com>2024-06-26 22:51:15 +0200
committerGitHub <noreply@github.com>2024-06-26 22:51:15 +0200
commit5f23dea1a1fa1708cc66d6aa951970bbd927515f (patch)
tree859216fde8fcba8ebbec05cf2323f7a7dee8a4a8 /lib/extensions/png_realistic.py
parentd2e571a3fbfa82baa1c0411fb4ee277692f574d3 (diff)
Make PNG (simple/realistic) and threadlist available in export file formats (#3019)
Diffstat (limited to 'lib/extensions/png_realistic.py')
-rw-r--r--lib/extensions/png_realistic.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/extensions/png_realistic.py b/lib/extensions/png_realistic.py
new file mode 100644
index 00000000..24ebce55
--- /dev/null
+++ b/lib/extensions/png_realistic.py
@@ -0,0 +1,32 @@
+# Authors: see git history
+#
+# Copyright (c) 2024 Authors
+# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
+
+import sys
+
+from ..stitch_plan import stitch_groups_to_stitch_plan
+from ..svg import render_stitch_plan
+from ..threads import ThreadCatalog
+from .base import InkstitchExtension
+from .png_simple import write_png_output
+
+
+class PngRealistic(InkstitchExtension):
+ def effect(self):
+ if not self.get_elements():
+ return
+
+ self.metadata = self.get_inkstitch_metadata()
+ collapse_len = self.metadata['collapse_len_mm']
+ min_stitch_len = self.metadata['min_stitch_len_mm']
+ stitch_groups = self.elements_to_stitch_groups(self.elements)
+ stitch_plan = stitch_groups_to_stitch_plan(stitch_groups, collapse_len=collapse_len, min_stitch_len=min_stitch_len)
+ ThreadCatalog().match_and_apply_palette(stitch_plan, self.get_inkstitch_metadata()['thread-palette'])
+
+ layer = render_stitch_plan(self.svg, stitch_plan, True, visual_commands=False, render_jumps=False)
+
+ write_png_output(self.svg, layer)
+
+ # don't let inkex output the SVG!
+ sys.exit(0)