Convert SVG to image (JPEG, PNG, etc.) in the browser

Zain picture Zain · Oct 20, 2010 · Viewed 321.7k times · Source

I want to convert SVG into bitmap images (like JPEG, PNG, etc.) through JavaScript.

Answer

jbeard4 picture jbeard4 · Oct 20, 2010

Here is how you can do it through JavaScript:

  1. Use the canvg JavaScript library to render the SVG image using Canvas: https://github.com/gabelerner/canvg
  2. Capture a data URI encoded as a JPG (or PNG) from the Canvas, according to these instructions: Capture HTML Canvas as gif/jpg/png/pdf?