Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8942479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:31:41+00:00 2026-06-15T11:31:41+00:00

I have been trying to convert an SVG image to a raster image. The

  • 0

I have been trying to convert an SVG image to a raster image. The format doesn’t matter, png or jpg would be nice though.

I am using jSignature to try an accomplish this. The API for jSignature isn’t clicking for me but I am at the point where I can draw a signature and post it into an <img src="data:" /> tag.

I have been reading other threads on SO discussing this issue and I have been trying this approach. However, I keep getting “Object [object Object] has no method ‘getContext’ ” errors from my console.

I will be passing this to a database using PHP.

<!DOCTYPE html>
<html>
  <head>
    <title></title>
    <link rel="stylesheet" type="text/css" href="sigStyle.css">
    <script type="text/javascript" src="jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="jSignature.min.js"></script>
    <script type="text/javascript">
      $(document).ready(function(){
        var sigdiv = $("#signature").jSignature({'UndoButton':true});

        $("#lock").click(function(){
          //Lock the canvas, stop user input
        });

        $("#save").click(function(){
          var datapair = sigdiv.jSignature("getData", "svgbase64");
          var i = new Image();
          i.src = "data:" + datapair[0] + "," + datapair[1];
          $(i).appendTo($("#outputSvg"));
        });

        $("#clear").click(function(){
          sigdiv.jSignature("reset");
          $("#outputSvg, #outputRaster").empty();
        });

        $("#raster").click(function(){
          var canvas = $("canvas").getContext("2d");
          var img = canvas.toDataURL("image/png");
          $("#outputRaster").append('<img src="'+img+'"/>');
        });
      })
    </script>
  </head>  
  <body>

    <div id="signature"></div>
    <br />
    <button id="lock">Lock</button>
    <button id="save">Save</button>
    <button id="clear">Clear</button>
    <button id="raster">Raster</button>
    <br /><br />
    <fieldset id="outputSvg" style="float:left">
      <legend>SVG</legend>
    </fieldset>
    <fieldset id="outputRaster" style="float:left">
      <legend>Raster</legend>
    </fieldset>
  </body>
</html>

Any help, advice or tips would be greatly appreciated! Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:31:43+00:00Added an answer on June 15, 2026 at 11:31 am

    I have figured it out!

    Canvg allows you to draw an svg to a canvas. I made a hidden canvas element on my page. I save my jSignature as an SVG/XML string, pass it to canvg to render, then finally utilize the hidden canvas’s .toDataURL() method.

     <head>
        <script type="text/javascript" src="jquery-1.7.2.min.js"></script>
        <script type="text/javascript" src="jSignature.min.js"></script>
        <script type="text/javascript" src="canvg.js"></script>
        <script>
         $(document).ready(function(){
            var sigdiv = $("#signature").jSignature({'UndoButton':true});
    
            $("#save").click(function(){
              var datapair = sigdiv.jSignature("getData", "svg");
              var i = new Image();
              i.src = "data:" + datapair[0] + "," + datapair[1];
              $(i).appendTo($("#outputSvg"));
    
              var canvas = document.getElementById("canvas");
    
              canvg(canvas, datapair[1]);
    
              var img = canvas.toDataURL("image/png");
              $("#outputRaster").append("<img src='"+img+"'/>");
            });
          });
        </script>
      </head>  
      <body>
        <div id="signature"></div>
        <canvas id="canvas" hidden="hidden"></canvas>
        <br />
        <button id="lock">Lock</button>
        <button id="save">Save</button>
        <button id="clear">Clear</button>
        <button id="raster">Raster</button>
        <br /><br />
        <fieldset id="outputSvg" style="float:left">
          <legend>SVG</legend>
        </fieldset>
        <fieldset id="outputRaster" style="float:left">
          <legend>Raster</legend>
        </fieldset>
      </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically on .show() I've been trying to have all of the inputs convert to
I have been trying to figure out a way to convert bitmap files into
I have been trying to convert my rails 2.2.2 app over to jQuery, and
I have been trying to convert sdot like this html_entity_decode(&sdot;); Any tips?
I have been trying to convert a simple execution such as: for x in
I have been trying for hours to convert this. I have tried looping through
I have a .NETCF project that I have been trying to convert from .NETCF
For the past few hours I have been trying to clone an image in
I have been trying for ages to convert a string taken from an input
I have been trying to figure out how to convert string below string to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.