question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to save created image to SVG file ?

See original GitHub issue

Is there a way to export a created image drawn using react-native-svg to a SVG file?

My goal is to:

  1. Use react-native-fs to write the SVG data to a SVG file.
  2. Reference the SVG image from HTML.
<html><body>
	<img src="http://phrogz.net/SVG/heart.svg" width="320" height="240">
</body></html>
  1. Convert HTML to PDF report using react-native-html-to-pdf.

I ran across a brief reference to a new method toDataURL.

While I think writing to a SVG file would be more versatile for PDF report generation, what format does toDataURL output to? SVG? PNG?

svgRef.toDataURL(base64 => {
    console.log(base64);
});

Thank you for a great component!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
petermikitshcommented, Mar 20, 2017

Exposing the toDataURL API, without having to place the element in the on-screen component tree, would be fantastic.

3reactions
esuttoncommented, Feb 6, 2018

For capturing a VictoryChart chart react-native-view-shot worked for me:

https://github.com/gre/react-native-view-shot

  onCaptureViewShot = (uri) => {
    const base64Data = uri;
    const profileImage = {
      uri: `data:image/png;base64,${base64Data}`,
      filePath: '',
    };
    this.props.onCreateFilesAndSend(profileImage);
  }    

  render() {
    const chart = this.renderChart();
    const renderChartOffScreen = this.state.creatingPdf ? chart : null;
    return (
      <View style={{ position: 'absolute', left: 0 }}>
        <ViewShot
          onCapture={this.onCaptureViewShot}
          captureMode="mount"
          options={{
            format: 'png',
            quality: 1.0,
            result: 'base64',
            }}
        >
          {renderChartOffScreen}
        </ViewShot>
      </View>
    );
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Convert JPG Images to SVG for Free | Adobe Express
1. Select. Choose a JPG image from your photo library that is less than 2GB in size.
Read more >
JPG to SVG (Online & Free) - Convertio
How to convert JPG to SVG. Step 1. Upload jpg-file(s). Select files from Computer, Google Drive, Dropbox, URL ...
Read more >
PNG to SVG: How to Create SVG Files for Cricut (with Pictures)
1. Open your Chrome browser, go to the Chrome Web Store and enter “File Converter - By Online-Convert.com” in your search bar, then...
Read more >
4 Ways to Convert Image to SVG File (Free Open Source Tools)
Open your image in Adobe Photoshop. · Go to File>Export>Export As. image to svg ps 1 · Choose SVG as the output format...
Read more >
How to Save Images (PNG, SVG, JPEG) – iphone, iPad ...
A. RIGHT CLICK on the LINK to the SVG image as shown below. In this example, you would right click on the text...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found