embiem / react-canvas-draw

React Component for drawing in canvas
https://embiem.github.io/react-canvas-draw/
MIT License
892 stars 315 forks source link

'getSaveData' feature: canvas to png and jpeg #67

Closed emizzz closed 2 years ago

emizzz commented 4 years ago

Added the "png" and "jpeg" save mode.

If 'getSaveData' is called without params, it behaves in the default way. If the argument is 'jpeg' or 'png', the method returns the data in the specified format.

embiem commented 4 years ago

Thanks a lot for this PR!

I'd like to have this as an addition to the API, instead of using getSaveData. E.g. you could add a getImageData() function, which uses the canvasToRasterImage function with the correct canvas ref.

Also, I'd like to add the ability to also save with the background image, if one is given. Right now, you'd only support using a custom background color, right?

Please let me know your thoughts and whether you can tackle these.

ern-arrowsmith commented 4 years ago

@emizzz @embiem if you want I could move this to a separate API? I am currently working on a project using this library and was just about to start working on export to PNG/JPEG when I spotted this PR.

embiem commented 4 years ago

Hey @ern-arrowsmith, thanks for the interest! Feel free to create a PR. If possible, I think it'd be good to have 3 options:

  1. Just the drawing,
  2. drawing + a custom background color (as implemented in this PR),
  3. drawing + the background image given in the props.

I'd also argue that exporting with the background image should be the default, if one was provided.

embiem commented 2 years ago

Closing this & will merge #78 as an extension to the already merged #97