I know that the question lasts 1 year and a half, but as of today there is a better solution. Hope this helps some other people find a way to save the image and remove the gray image from the unusual jSignature plugin.
The best approach is here: http://www.reloadedpc.com/php/jquery-jsignature-php-base30-image/
<?php // Load jSignature library to con require_once(dirname(__FILE__) . '/jSignature_Tools_Base30.php'); // Get signature string from _POST or _GET $data = $_GET['signature']; $data = str_replace('image/jsignature;base30,', '', $data); // Create jSignature object $signature = new jSignature_Tools_Base30(); // Decode base30 format $a = $signature->Base64ToNative($data); // Create a image $im = imagecreatetruecolor(1295, 328); // Save transparency for PNG imagesavealpha($im, true); // Fill background with transparency $trans_colour = imagecolorallocatealpha($im, 0, 0, 0, 127); imagefill($im, 0, 0, $trans_colour); // Set pen thickness imagesetthickness($im, 5); // Set pen color to blue $blue = imagecolorallocate($im, 0, 0, 255); // Loop through array pairs from each signature word for ($i = 0; $i < count($a); $i++) { // Loop through each pair in a word for ($j = 0; $j < count($a[$i]['x']); $j++) { // Make sure we are not on the last coordinate in the array if ( ! isset($a[$i]['x'][$j]) or ! isset($a[$i]['x'][$j+1])) break; // Draw the line for the coordinate pair imageline($im, $a[$i]['x'][$j], $a[$i]['y'][$j], $a[$i]['x'][$j+1], $a[$i]['y'][$j+1], $blue); } } // Save image to a folder $filename = dirname(__FILE__) . '/signature.png'; // Make folder path is writeable imagepng($im, $filename); // Removing $filename will output to browser instead of saving echo $filename; // Clean up //imagedestroy($im);
? >
As the author said:
“The base30 string format allows the user to save the string in the database and reuse later if this application requires. The base30 string is very small for the amount of data that is saved. Fortunately, the jSignature download includes a shell that decodes the base30 string into an array of vector points.
Using the code above, you can take base30 input from jSignature and create a PNG file without formatting the signature line . This makes it possible to save the string in MySQL , and then transfer the image to the browser when you need to. I used this method in conjunction with the PDF DOM to sign the PDF file "
I mean, what do you want more? No image or batik or jSignature kernel code changes. Just the perfect solution! Thanks a lot ReloadedPC
Edit: The only problem with this approach is that it doesn't work for iOS. You must use base64. The idea is the same.