2

I have a div which I'm applying the jSignature plugin to with

var $sigdiv = $(".jsig")
$sigdiv.jSignature() // inits the jSignature widget.

I have a button to capture this to base64 then pass it to PHP to create the image on the server.

$sig=$("#signature");
alert($sig.jSignature("getData"));

getData returns base64 for a PNG but I need a jpeg and I can't get it to work. Has anybody come across a workaround please.

Graham
  • 57
  • 1
  • 11

1 Answers1

0

As of jSignature v2 "2016-11-05T00:40" I couldn't find a way to export JPEG data with jSignature without modifying the component code.

By applying this modification jSignature('getData') method with default export option will always export JPEG instead of PNG.

Alternatively you can enchance the exportplugins class in component code and add more export options to it.

Solution:

in jSignature.js or jSignature.min.js search for

{return this.toDataURL()}

and change it to

{return this.toDataURL('image/jpeg', 0.8)}

which 0.8 is the image quality and can be from 0.1 to 1.0.

HTMLCanvasElement.toDataURL() explains other available options.

AaA
  • 3,600
  • 8
  • 61
  • 86