Download the PHP package liquidedge-app/signature_pad without Composer
On this page you can find all versions of the php package liquidedge-app/signature_pad. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package signature_pad
Signature Pad

Signature Pad is a JavaScript library for drawing smooth signatures. It's HTML5 canvas based and uses variable width Bézier curve interpolation based on Smoother Signatures post by Square. It works in all modern desktop and mobile browsers and doesn't depend on any external libraries.

Demo
Demo works in desktop and mobile browsers. You can check out its source code for some tips on how to handle window resize and high DPI screens. You can also find more about the latter in HTML5 Rocks tutorial.
Other demos
- Erase feature: https://jsfiddle.net/UziTech/xa91e4Lp/
- Undo feature: https://jsfiddle.net/szimek/osenxvjc/
Installation
You can install the latest release using npm:
or Yarn:
You can also add it directly to your page using <script> tag:
You can select a different version at https://www.jsdelivr.com/package/npm/signature_pad.
This library is provided as UMD (Universal Module Definition) and ES6 module.
Usage
API
Options
- dotSize
- (float or function) Radius of a single dot. Also the width of the start of a mark.
- minWidth
- (float) Minimum width of a line. Defaults to
0.5. - maxWidth
- (float) Maximum width of a line. Defaults to
2.5. - throttle
- (integer) Draw the next point at most once per every
xmilliseconds. Set it to0to turn off throttling. Defaults to16. - minDistance
- (integer) Add the next point only if the previous one is farther than
xpixels. Defaults to5. - backgroundColor
- (string) Color used to clear the background. Can be any color format accepted by
context.fillStyle. Defaults to"rgba(0,0,0,0)"(transparent black). Use a non-transparent color e.g."rgb(255,255,255)"(opaque white) if you'd like to save signatures as JPEG images. - penColor
- (string) Color used to draw the lines. Can be any color format accepted by
context.fillStyle. Defaults to"black". - velocityFilterWeight
- (float) Weight used to modify new velocity based on the previous velocity. Defaults to
0.7. - canvasContextOptions
- (CanvasRenderingContext2DSettings) part of the Canvas API, provides the 2D rendering context for the drawing surface of a
canvaselement. It is used for drawing shapes, text, images, and other objects (MDN).
You can set options during initialization:
or during runtime:
Events
- beginStroke
- Triggered before stroke begins.
Can be canceled withevent.preventDefault() - endStroke
- Triggered after stroke ends.
- beforeUpdateStroke
- Triggered before stroke update.
- afterUpdateStroke
- Triggered after stroke update.
You can add listeners to events with .addEventListener:
Tips and tricks
Handling high DPI screens
To correctly handle canvas on low and high DPI screens one has to take devicePixelRatio into account and scale the canvas accordingly. This scaling is also necessary to properly display signatures loaded via SignaturePad#fromDataURL. Here's an example how it can be done:
Instead of resize event you can listen to screen orientation change, if you're using this library only on mobile devices. You can also throttle the resize event - you can find some examples on this MDN page.
Handling canvas resize
When you modify width or height of a canvas, it will be automatically cleared by the browser. SignaturePad doesn't know about it by itself, so you can call signaturePad.fromData(signaturePad.toData()) to reset the drawing, or signaturePad.clear() to make sure that signaturePad.isEmpty() returns correct value in this case.
This clearing of the canvas by the browser can be annoying, especially on mobile devices e.g. when screen orientation is changed. There are a few workarounds though, e.g. you can lock screen orientation, or read an image from the canvas before resizing it and write the image back after.
Handling data URI encoded images on the server side
If you are not familiar with data URI scheme, you can read more about it on Wikipedia.
There are 2 ways you can handle data URI encoded images.
You could simply store it in your database as a string and display it in HTML like this:
but this way has many disadvantages - it's not easy to get image dimensions, you can't manipulate it e.g. to create a thumbnail and it also has some performance issues on mobile devices.
Thus, more common way is to decode it and store as a file. Here's an example in Ruby:
Here's an example in PHP:
Here's an example in C# for ASP.NET:
Removing empty space around a signature
If you'd like to remove (trim) empty space around a signature, you can do it on the server side or the client side. On the server side you can use e.g. ImageMagic and its trim option: convert -trim input.jpg output.jpg. If you don't have access to the server, or just want to trim the image before submitting it to the server, you can do it on the client side as well. There are a few examples how to do it, e.g. here or here and there's also a tiny library trim-canvas that provides this functionality.
Drawing over an image
Demo: https://jsfiddle.net/szimek/d6a78gwq/
License
Released under the MIT License.