I'm developing an Inkscape extension to optimize clipped images in an SVG document. The basic idea is to:
Export each clipped image as a PNG to a temporary file.
Re-import the PNG image back into the SVG.
Position the re-imported image correctly based on the original clipped image's position and clip path.
Delete the original clipped image and its clip path.
I've successfully implemented the export functionality using the subprocess module and Inkscape's command-line options. However, I'm encountering difficulties with the image import step.
Here are the methods I've tried so far:
subprocess.run() with --import-filename: This seems to import the image, but it doesn't consistently appear in the SVG document, and I'm having trouble accessing and manipulating the imported image element using the inkex API.
inkex.etree.SubElement(): This method throws an error saying that inkex has no attribute etree.
self.svg.Element(): This also throws an error, stating that SvgDocumentElement has no attribute Element.
etree.SubElement(): This method seems to be the closest to working, but I'm still having trouble reliably accessing and positioning the imported image element.
I'm using Inkscape 1.3.2 on Windows 11.
Could anyone provide guidance or suggestions on how to reliably import images into an SVG document using the Inkscape extension API? Are there any specific considerations or best practices I should be aware of?
Hi everyone,
I'm developing an Inkscape extension to optimize clipped images in an SVG document. The basic idea is to:
I've successfully implemented the export functionality using the
subprocess
module and Inkscape's command-line options. However, I'm encountering difficulties with the image import step.Here are the methods I've tried so far:
subprocess.run()
with--import-filename
: This seems to import the image, but it doesn't consistently appear in the SVG document, and I'm having trouble accessing and manipulating the imported image element using theinkex
API.inkex.etree.SubElement()
: This method throws an error saying thatinkex
has no attributeetree
.self.svg.Element()
: This also throws an error, stating thatSvgDocumentElement
has no attributeElement
.etree.SubElement()
: This method seems to be the closest to working, but I'm still having trouble reliably accessing and positioning the imported image element.I'm using Inkscape 1.3.2 on Windows 11.
Could anyone provide guidance or suggestions on how to reliably import images into an SVG document using the Inkscape extension API? Are there any specific considerations or best practices I should be aware of?
Any help would be greatly appreciated!