Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to download / export a rendered smiles as an image #181

Open
MurhafSousli opened this issue Jan 18, 2024 · 1 comment
Open

How to download / export a rendered smiles as an image #181

MurhafSousli opened this issue Jan 18, 2024 · 1 comment

Comments

@MurhafSousli
Copy link

I want to implement a download button next to the smiles, I use SVG to render the smiles. but I am wondering if I can be able to download an image format like PNG of the smiles

drawImage() {
  const drawer = new SmilesDrawer.SvgDrawer();

  SmilesDrawer.parse(
     this.smiles,
     (tree: any) => {
        drawer.draw(tree, this.svgElement.nativeElement, 'light');
      },
      (err: Error) => {
         this.smileFailed = true;
       }
   );
}

Should I use an img element, an inline data or BLOB that can be used to make the download?

@MurhafSousli MurhafSousli changed the title How to export a rendered smiles as an image How to download / export a rendered smiles as an image Jan 18, 2024
@Acylation
Copy link

Acylation commented Feb 22, 2024

https://github.com/Acylation/obsidian-chem/blob/599af5988e79eb308ab702d61b6f4cae7f627534/src/SmilesBlock.ts#L191

The onCopy function can transfer svg dom string (fetched from outerHTML() of SVGSVGElement) to img/png blob object in clipboard. Please ignore the UI code irrelated to this package. Feel free to follow-up if there's something unclear.

Also canvas renderer provides more flexibility. Ref: #89

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants