EmbroidePy / pyembroidery

pyembroidery library for reading and writing a variety of embroidery formats.
MIT License
195 stars 35 forks source link

Change color of generated PNG Question #137

Open MaveCritDev opened 2 years ago

MaveCritDev commented 2 years ago

Hello! Firstly: Happy new year and thank you very much for this library. Right now, this is the only one I was able to find on the whole web. Please excuse any dumb mistakes. Actually this is my first ever python project. And now I have a question about this :)

Probably its best if I just explain briefly what I'm trying to achieve and what I already have: We do embroidery for endusers. They can send us their dst files but right now we have to call them after to clarify every color we should use. I want to automate this a bit.

What I have I made a simple react frontend in which the users can upload their dst files. After the upload I call a pyembroidery script on the backend to generate a png preview of this file. Since DST does not contain any color informations I initially transform it to a PES. After that I generate a initial preview PNG of the PES and send the informations of pattern.threadList() back to the frontend. Now in the frontend the user is able to adjust the threadcolors using the threadList of the previously generated pes file.

What I'm trying to achieve Use the hexa values the user selectes in the frontend and update the PES file to generate a new PNG with provided colors. So lets say the original .threadList() is: [EmbThread(thread='#00000', description='Magenta', catalog_number='7', brand='Brother', chart='Brother'), EmbThread(thread='#FFFFF', description='Mint Green', catalog_number='10', brand='Brother', chart='Brother')] And my new hexa colors array looks like this: ['#238636', '#433636']

How can I override the threadList? Something like threadList()[0].thread = newThreadColors[0] (The descriptions and all other thread infos are not relevant to me since the file is only used to generate a preview PNG) Is this possible?

Again sorry, I never touched Python yet. Probably its super simple but I'm just not knowing it.

Thank you very much for every help, I appreciate :)

Greeting from Germany, Philipp

tatarize commented 2 years ago

To change the value in thread 0 you would call: pattern.threadlist[0].set_hex_color('#238636')

And for thread 1: pattern.threadlist[1].set_hex_color('#433636')

tatarize commented 2 years ago

Notably this isn't covered in the readme, so it is an oversight on my part.

MaveCritDev commented 2 years ago

Thank you very very much! With your help I was able to generate and update preview files exactly how I wanted it! It might be a bit nested & somehow messy since I fire a POST to a SpringBoot backend which then calls the python script using processbuilder but thats the only solution I could come up with (Every color change also needs to be updated in the db)

I already said it and I will repeat it with joy: Thank you for your work. (And also I want to note that I'm amazed how fast you answered.)

Thank you!

image