javascriptsvg

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


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


Solution

  • 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?