reymond-group / smilesDrawer

A small, highly performant JavaScript component for parsing and drawing SMILES strings. Released under the MIT license.
https://smilesdrawer.rocks
MIT License
434 stars 68 forks source link

Is there a way to get the result as Image instead of rendering to canvas? #89

Open thangaraja opened 4 years ago

thangaraja commented 4 years ago

Hi,

I am working on a project in which the SMILE need to be prepared as the API. So the UI can be handled by the consuming application.

Is there a way to generate the result as an image?

robertf224 commented 4 years ago

@thangaraja you could grab the context of the canvas after rendering and use getImageData (https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/getImageData)

robertf224 commented 4 years ago

or if you're going to render the image with an image tag you can use toDataUrl https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL