简体   繁体   English

如何从jSignature插件中的CANVAS中删除灰色线?

[英]How to remove grey color line from CANVAS in the jSignature plugin?

How to remove grey color line from CANVAS (Signature panel) in the jSignature plugin ? 如何从jSignature plugin中的CANVAS(签名面板)中删除灰色线?

Is there any option to validate whether user enter signature or not ? 是否有任何选项可以验证用户是否输入签名? Any built in function for this ? 这有什么内置功能吗?

http://willowsystems.github.com/jSignature/#/demo/ http://willowsystems.github.com/jSignature/#/demo/

How about this setting the decor-color to transparent 如何将装饰颜色设置为透明

$(document).ready(function() {
        $("#signature").jSignature({
            'background-color': 'transparent',
            'decor-color': 'transparent',
        });
    });

I am afraid there is no option to turn it off, so the only solution would be to change the plug-in code itself 我担心没有选择关闭它,所以唯一的解决方案是更改插件代码本身

There is a section in the plug-in that draws the base line. 插件中有一个部分用于绘制基线。 Just comment out like this 就这样评论吧

// signature line
ctx.strokeStyle = settings['decor-color']
ctx.shadowOffsetX = 0
ctx.shadowOffsetY = 0
var lineoffset = Math.round( ch / 5 )
//basicLine(ctx, lineoffset * 1.5, ch - lineoffset, cw - (lineoffset * 1.5), ch - lineoffset)
ctx.strokeStyle = settings.color

If you are using jSignature v2 (Version 2), 如果您使用的是jSignature v2(版本2),

c.lineTo(l, i); - comment this line to remove the grey line in the canvas. - 注释此行以删除画布中的灰线。

Below code works 下面的代码工作

r.prototype.resetCanvas = function (b) {
    var a = this.canvas,
        d = this.settings,
        c = this.canvasContext,
        f = this.isCanvasEmulator,

        .........................

        c.shadowOffsetY = 0;
    var h = Math.round(i / 5),
        p = 1.5 * h,
        k = i - h,
        l = l - 1.5 * h,
        i = i - h;
    c.beginPath();
    c.moveTo(p, k);
    //c.lineTo(l, i); // comment this line to remove the grey line in the canvas.
    c.stroke();
    c.strokeStyle = d.color;
    f || (c.shadowColor = c.strokeStyle, c.shadowOffsetX = 0.5 * c.lineWidth, c.shadowOffsetY = -0.6 * c.lineWidth, c.shadowBlur = 0);

    ..........................
};

I made the following changes to jSignature in my project: 我在项目中对jSignature进行了以下更改:

showLine: true, //added showLine in default options

c.showLine = d.showLine; 
if(c.showLine){
  c.lineTo(l, i); 
}

Then I pass true or false when I do 然后,当我这样做时,我会传递truefalse

$('#signature').jSignature({ color: "#00f", lineWidth: 3, showLine: false });

Now I have the option to show it or hide it. 现在我可以选择显示或隐藏它。

This is probably too late but hope it helps someone else stumbling on this. 这可能为时已晚,但希望它可以帮助其他人绊倒这个。 I've added some code to disable the grey line if you pass decor-color as null when initialising it. 如果在初始化时将decor-color作为null传递,我添加了一些禁用灰线的代码。 I prefer this approach then to add another attribute to enable/disable the signature line. 我更喜欢这种方法,然后添加另一个属性来启用/禁用签名行。

   // signature line
-  ctx.strokeStyle = settings['decor-color'];
-  ctx.shadowOffsetX = 0;
-  ctx.shadowOffsetY = 0;
-  var lineoffset = Math.round( ch / 5 );
-  basicLine(ctx, lineoffset * 1.5, ch - lineoffset, cw - (lineoffset * 1.5), ch - lineoffset);
+  if (null != settings['decor-color']) {
+    ctx.strokeStyle = settings['decor-color'];
+    ctx.shadowOffsetX = 0;
+    ctx.shadowOffsetY = 0;
+    var lineoffset = Math.round( ch / 5 );
+    basicLine(ctx, lineoffset * 1.5, ch - lineoffset, cw - (lineoffset * 1.5), ch - lineoffset);
+  }

   ctx.strokeStyle = settings.color;

It is in my git repo at https://github.com/brinley/jSignature 它是在我的git repo https://github.com/brinley/jSignature

I know the question is 1 year and a half old but as today there is a better solution. 我知道问题是1年半,但今天有一个更好的解决方案。 Hope this will help some other people searching for a way to save the image and remove the gray line from jSignature extraordinary plugin. 希望这将有助于其他人寻找保存图像的方法,并从jSignature 非凡插件中删除灰线。

The better approach here: http://www.reloadedpc.com/php/jquery-jsignature-php-base30-image/ 这里更好的方法是: 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 a user to save the string in the database , and reuse later if you application requires that. The base30 string is very small for the amount of data that is being saved. Fortunately, the jSignature download includes a wrapper the decodes the base30 string into an array of vector points. base30字符串格式允许用户将字符串保存在数据库中 ,如果应用程序需要,则稍后重复使用.base30字符串对于正在保存的数据量非常小 。幸运的是,jSignature下载包含一个包装器将base30字符串解码为矢量点数组。

Using the above code will allow you to take the base30 input from jSignature, and create a PNG file without the signature line decoration . 使用上面的代码将允许您从jSignature获取base30输入,并创建一个没有签名行装饰的PNG文件 This provides a way to save the string in MySQL , and then stream the image to the browser when you need to. 这提供了一种在MySQL中保存字符串的方法,然后在需要时将图像流式传输到浏览器 I used this technique combined with DOM PDF to render the signature in a PDF file " 我使用这种技术结合DOM PDF来呈现PDF文件中的签名

I mean, what you want more than that? 我的意思是,你想要的不止于此? No imagick or batik or changing the jSignature core code. 没有想象力或蜡染或更改jSignature核心代码。 Just perfect solution! 完美的解决方案! Many thanks to ReloadedPC 非常感谢ReloadedPC

Edit: the only problem with this approach is that is not working for iOS. 编辑:这种方法的唯一问题是不适用于iOS。 You have to use base64. 你必须使用base64。 The idea is the same. 这个想法是一样的。

Author does have provided option to remove grey line but seems the code is not checked-in. 作者确实提供了删除灰线的选项,但似乎代码未签入。 Visit to this location https://github.com/willowsystems/jSignature/pull/17/files and look for 'Files Changed' tab. 访问此位置https://github.com/willowsystems/jSignature/pull/17/files并查找“Files Changed”选项卡。

Under the tab- you'll find deleted lines with pink background and (-) minus sign and added lines with green background and (+) plus sign. 在选项卡下 - 您将找到带有粉红色背景和( - )减号的删除行,并添加带绿色背景和(+)加号的行。 You need to change the source by yourself. 您需要自己更改源。 Something like this 像这样的东西

    // signature line
    //ctx.strokeStyle = settings['decor-color']
    //ctx.shadowOffsetX = 0
    //ctx.shadowOffsetY = 0
    //var lineoffset = Math.round(ch / 5)
    //basicLine(ctx, lineoffset * 1.5, ch - lineoffset, cw - (lineoffset * 1.5), ch - lineoffset)
    //ctx.strokeStyle = settings.color


    //if (!isCanvasEmulator) {
    //    ctx.shadowColor = ctx.strokeStyle
    //    ctx.shadowOffsetX = ctx.lineWidth * 0.5
    //    ctx.shadowOffsetY = ctx.lineWidth * -0.6
    //    ctx.shadowBlur = 0


    if (settings.signatureLine) {
        ctx.strokeStyle = settings['decor-color']
        ctx.shadowOffsetX = 0
        ctx.shadowOffsetY = 0
        var lineoffset = Math.round(ch / 5)
        basicLine(ctx, lineoffset * 1.5, ch - lineoffset, cw - (lineoffset * 1.5), ch - lineoffset)
        ctx.strokeStyle = settings.color

        if (!isCanvasEmulator) {
            ctx.shadowColor = ctx.strokeStyle
            ctx.shadowOffsetX = ctx.lineWidth * 0.5
            ctx.shadowOffsetY = ctx.lineWidth * -0.6
            ctx.shadowBlur = 0
        }
    }

Once code changes done ... initiate the jSignature object 完成代码更改后...启动jSignature对象

 $('#signature').jSignature({
    'signatureLine': false
});

In case sombody still has a problem with this and uses the nonconflict version from the website from the author. 如果sombody仍然有问题,并使用来自作者网站的非冲突版本。 This solved it for me: 这解决了我:

Comment the following part in line 54 of jSignature.min.nonconflict.js 在jSignature.min.nonconflict.js的第54行中注释以下部分

/*c.beginPath();c.moveTo(p,k);c.lineTo(l,i);c.stroke()*/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM