Код: Выделить всё
process = subprocess.Popen([INKSCAPE_EXE_PATH, "--shell"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, shell=True)
def create_image_data(SVGs):
# Loop through all SVGs
for svg in SVGs:
# Create a temporary SVG file
with tempfile.NamedTemporaryFile(delete=False, suffix='.svg') as temp_svg:
temp_svg.write(svg.encode('utf-8'))
temp_svg_path = temp_svg.name
# Add commands to the list
process.stdin.write(f"file-open:{temp_svg_path}\n")
process.stdin.flush() # Flush to ensure the command is sent
# Export the image
process.stdin.write(f"export-filename:{os.path.join(os.getcwd(), f'{filename}-{page}.png')}\n")
process.stdin.write("export-do\n")
process.stdin.flush() # Make sure to flush the input buffer
process.stdin.write("query-all\n") # TODO get this output only
process.stdin.flush()
process.stdin.write("quit\n")
# Call the function with your input file
create_image_data(LIST_OF_SVGs)
Подробнее здесь: https://stackoverflow.com/questions/790 ... shell-mode
Мобильная версия