Sangram
Sangram

Reputation: 354

Python How to convert DST file into PNG file?

I have looked around and read the docs about pyembroidery, and i am confused , so I ask here. Is there any packages available to use Python to convert a DST image to a PNG image?

img.py

import pyembroidery
pattern = pyembroidery.read_dst("shamrockin.dst")
pyembroidery.write_png(pattern, 'shamrockin.dst')

Error

pattern = pyembroidery.read_dst("shamrockin.dst",)
File "/home/panacea/Documents/src/easy tailor/EasyTailor/venv/lib/python3.5/site-packages/pyembroidery/PyEmbroidery.py", line 462, in read_dst reader.read(stream, pattern, settings) File "/home/panacea/Documents/src/easy tailor/EasyTailor/venv/lib/python3.5/site-packages/pyembroidery/DstReader.py", line 86, in read dst_read_header(f, out) File "/home/panacea/Documents/src/easy tailor/EasyTailor/venv/lib/python3.5/site-packages/pyembroidery/DstReader.py", line 55, in dst_read_header header_string = header.decode('utf8') UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte

Upvotes: 1

Views: 1105

Answers (1)

Warren Weckesser
Warren Weckesser

Reputation: 114811

You write the PNG file to 'shamrockin.dst', which overwrites the original file. When you run this a second time, 'shamrockin.dst' is now a PNG file, so it can not be read with read_dst. (A clue is in the error message UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte: the byte 0x89 is always the first byte of a PNG file.)

Restore your original DST file, and change

pyembroidery.write_png(pattern, 'shamrockin.dst')

to

pyembroidery.write_png(pattern, 'shamrockin.png')

Upvotes: 4

Related Questions