fix in export selection as
This commit is contained in:
parent
ab25f2ad94
commit
9d00a29d83
@ -202,7 +202,20 @@ class ExportObject(inkex.EffectExtension):
|
|||||||
self.msg(cli_output)
|
self.msg(cli_output)
|
||||||
|
|
||||||
if self.options.export_png is True:
|
if self.options.export_png is True:
|
||||||
cli_output = inkscape(os.path.join(tempfile.gettempdir(), svg_filename), extra_param, actions='export-background:white;export-filename:{file_name};export-do'.format(file_name=os.path.join(export_dir, filename_base + '.png')))
|
png_export=os.path.join(export_dir, filename_base + '.png')
|
||||||
|
try:
|
||||||
|
os.remove(png_export)
|
||||||
|
except OSError as e:
|
||||||
|
#inkex.utils.debug("Error while deleting previously generated output file " + png_export)
|
||||||
|
pass
|
||||||
|
actions_list=[]
|
||||||
|
actions_list.append("export-background:white")
|
||||||
|
actions_list.append("export-type:png")
|
||||||
|
actions_list.append("export-dpi:{}".format(self.options.png_dpi))
|
||||||
|
actions_list.append("export-filename:{}".format(png_export))
|
||||||
|
actions_list.append("export-do")
|
||||||
|
actions = ";".join(actions_list)
|
||||||
|
cli_output = inkscape(os.path.join(tempfile.gettempdir(), svg_filename), extra_param, actions=actions)
|
||||||
if len(cli_output) > 0:
|
if len(cli_output) > 0:
|
||||||
self.msg("Inkscape returned the following output when trying to run the file export; the file export may still have worked:")
|
self.msg("Inkscape returned the following output when trying to run the file export; the file export may still have worked:")
|
||||||
self.msg(cli_output)
|
self.msg(cli_output)
|
||||||
@ -215,19 +228,17 @@ class ExportObject(inkex.EffectExtension):
|
|||||||
except OSError as e:
|
except OSError as e:
|
||||||
#inkex.utils.debug("Error while deleting previously generated output file " + png_export)
|
#inkex.utils.debug("Error while deleting previously generated output file " + png_export)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
actions_list=[]
|
actions_list=[]
|
||||||
actions_list.append("export-background:white")
|
actions_list.append("export-background:white")
|
||||||
actions_list.append("export-type:png")
|
actions_list.append("export-type:png")
|
||||||
actions_list.append("export-dpi:{}".format(self.options.png_dpi))
|
actions_list.append("export-dpi:{}".format(self.options.png_dpi))
|
||||||
actions_list.append("export-filename:" + png_export)
|
actions_list.append("export-filename:{}".format(png_export))
|
||||||
actions_list.append("export-do")
|
actions_list.append("export-do")
|
||||||
actions = ";".join(actions_list)
|
actions = ";".join(actions_list)
|
||||||
cli_output = inkscape(os.path.join(tempfile.gettempdir(), svg_filename), extra_param, actions=actions)
|
cli_output = inkscape(os.path.join(tempfile.gettempdir(), svg_filename), extra_param, actions=actions)
|
||||||
if len(cli_output) > 0:
|
if len(cli_output) > 0:
|
||||||
self.msg("Inkscape returned the following output when trying to run the file export; the file export may still have worked:")
|
self.msg("Inkscape returned the following output when trying to run the file export; the file export may still have worked:")
|
||||||
self.msg(cli_output)
|
self.msg(cli_output)
|
||||||
|
|
||||||
#then remove the selection and replace it by png
|
#then remove the selection and replace it by png
|
||||||
#self.msg(parent.get('id'))
|
#self.msg(parent.get('id'))
|
||||||
for elem in selected.values():
|
for elem in selected.values():
|
||||||
@ -238,7 +249,6 @@ class ExportObject(inkex.EffectExtension):
|
|||||||
img.save(output_buffer, format='PNG')
|
img.save(output_buffer, format='PNG')
|
||||||
byte_data = output_buffer.getvalue()
|
byte_data = output_buffer.getvalue()
|
||||||
base64_str = base64.b64encode(byte_data).decode('UTF-8')
|
base64_str = base64.b64encode(byte_data).decode('UTF-8')
|
||||||
|
|
||||||
#finally replace the svg:path(s) with svg:image
|
#finally replace the svg:path(s) with svg:image
|
||||||
imgReplacement = etree.SubElement(Rectangle(), '{http://www.w3.org/2000/svg}image')
|
imgReplacement = etree.SubElement(Rectangle(), '{http://www.w3.org/2000/svg}image')
|
||||||
imgReplacement.attrib['x'] = str(bbox.left)
|
imgReplacement.attrib['x'] = str(bbox.left)
|
||||||
@ -248,6 +258,7 @@ class ExportObject(inkex.EffectExtension):
|
|||||||
imgReplacement.attrib['id'] = firstId
|
imgReplacement.attrib['id'] = firstId
|
||||||
imgReplacement.attrib['{http://www.w3.org/1999/xlink}href'] = "data:image/png;base64,{}".format(base64_str)
|
imgReplacement.attrib['{http://www.w3.org/1999/xlink}href'] = "data:image/png;base64,{}".format(base64_str)
|
||||||
parent.append(imgReplacement)
|
parent.append(imgReplacement)
|
||||||
|
del parent.attrib['transform'] #remove transform
|
||||||
|
|
||||||
|
|
||||||
def create_document(self):
|
def create_document(self):
|
||||||
|
Reference in New Issue
Block a user