viliusle / miniPaint

online image editor
http://viliusle.github.io/miniPaint/
Other
2.74k stars 634 forks source link

Best way to save an image in an HTML form? Or: Is there an onChange event? #237

Closed flange-ipb closed 3 years ago

flange-ipb commented 3 years ago

Hello, first of all thanks for creating such an advanced image editor!

I'd like to integrate miniPaint into an HTML form and write its data into a hidden input field. The open-edit-save example shows nicely how data can be written. My question: When to do this?

Any suggestions/ideas?

Best regards, Frank

viliusle commented 3 years ago

Hello,

  1. Trying to export JSON on each update (on_update/render is executed from 25/30 times per second to 0, depends on user actions) would end with extra lag for user. If using big images, lag would be huge. I would suggest try to avoid it.
  2. Using extra button to save state sounds best way to do it.
viliusle commented 3 years ago
  1. (even better) If you are using form, you can even save state just before form submit.
flange-ipb commented 3 years ago

Ok, thanks! Solution 2. or 3. work nicely. First, I tried to put the exported JSON data into an <input type="hidden">, which seems to have the same content size limitations like <input type="text"> - thus, large images cannot be sent. I managed to send the data embedded in a Blob object via a <input type="file"> now.