将Topaz Sigweb sigstring转换为Base64 [英] Convert Topaz Sigweb sigstring to Base64

查看:80
本文介绍了将Topaz Sigweb sigstring转换为Base64的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个移动应用程序(离子),其中有一个供用户签名的字段.用户需要用手指在画布上签名.

I am working on a mobile application(ionic) where there is a field for user's signature. Users needs to sign with their finger in canvas.

现在此应用程序具有Web版本,他们在该版本中使用topaz sigweb进行此操作.现在要保存签名并在两端查看,我需要某种转换.

Now this application has web version, where they used topaz sigweb to do this. Now to save signature and to view in both ends i need some kind of conversion.

我检查了sigweb的文档,他们将签名保存为ASCHII十六进制格式.我不确定他们是否使用任何类型的内部加密,因为我无法将十六进制字符串转换为任何有效的基数64.

I checked sigweb's documentation, they save the signature in ASCHII hex format. I am not sure if they are using any kind of internal encryption or not because i can not convert the hex string to any valid base 64.

我不确定是否还有其他方法可以做到这一点.如果有人有任何想法,请分享.

I am not sure if there are any other way to do that. If anyone has any idea please share.

谢谢.

推荐答案

我意识到这有点老了,但是我敢肯定还有很多其他人遇到同样的问题.

I realise this is a bit old but I'm sure there are plenty of others with the same issue.

当我需要在不需要插件或安装的标准台式机或移动浏览器中向最终用户显示签名时,我遇到了完全相同的问题.谈到Topaz,有一个选项可以使用PHP组件对象模型在服务器端运行ActiveX来创建映像.不幸的是,这仅在Windows服务器上有效,并且需要花费很多时间.我只设法使其在我的测试台上工作,这对我的linux生产服务器毫无用处.我再次联系了Topaz,他们说唯一的选择是Java applet!?

I had exactly the same issues when I needed to display the signatures to end users in a standard desktop or mobile browser with no plug-ins or installs required. Spoke to Topaz and there is a an option to run the ActiveX on the server side using the PHP Component Object Model to create the image. Unfortunately, this only works on a Windows server and takes a lot of fiddling with. I only managed to get it working on my test bench and it was useless for my linux production servers. I contacted Topaz again and they said the ONLY other option was a Java applet!?

ActiveX!Java Applets!这是2019年,而不是2009年!(对不起,我在那儿加了惊叹号,但是杰兹).

ActiveX! Java Applets! It's 2019, not 2009! (Sorry, I overdosed on exclamation marks there but Jeez).

最后,我决定自己尝试对其进行解码,并最终提出了此PHP函数来创建SVG.他们使用的格式是专有的(实际上有点乱七八糟),但是本质上只有十六进制,坐标和笔划长度-因此,对于他人来说,将以下内容转换为任何其他平台应该足够容易.

In the end I decided to try and decode it myself and eventually came up with this PHP function to create an SVG. The format they use is proprietary (and is actually a bit of a hacky mess) but essentially it is only hex, coordinates and stroke lengths - so it should be easy enough for someone to convert the below to any other platform.

//Requires $SigString and accepts optional filename.
//If filename is supplied the image will be written to that file
//If no filename is supplied the SVG image will be returned as a string which can be echoed out directly

function sigstring2svg($SigString, $filename = NULL)
{
    $raw = hex2bin($SigString); //Convert Hex
    $arr = explode(PHP_EOL, $raw); //Split into array
    if ($arr[1] > 0) { //Check if signature is empty
        $coords = array_slice($arr, 2, $arr[0]); //Separate off coordinate pairs
        $lines = array_slice($arr, ($arr[0] + 2), $arr[1]); //Separate off number of coordinates pairs per stroke
        if ($arr[1] == 1) {
            $lines[] = ($arr[0] + 2); //If there is only 1 line the end has to be marked
        }
        $done = 0;
        foreach ($lines as $line => $linevalue) {
            if ($linevalue > $done) {
                $strokes[$line] = array_slice($coords, $done, $linevalue); //Split coordinate pairs into separate strokes
            }
            $done = $linevalue;
        }
        //Split X and Y to calculate the maximum and minimum coordinates on both axis
        $xmax = 0;
        $xmin = 999999;
        $ymax = 0;
        $ymin = 999999;
        foreach ($strokes as $stroke => $xycoords) {
            foreach ($xycoords as $xycoord) {
                $xyc = explode(' ', $xycoord);
                $xy[$stroke]['x'][] = $xyc[0];
                if ($xyc[0] > $xmax) $xmax = $xyc[0];
                if ($xyc[0] < $xmin) $xmin = $xyc[0];
                $xy[$stroke]['y'][] = $xyc[1];
                if ($xyc[1] > $ymax) $ymax = $xyc[1];
                if ($xyc[1] < $ymin) $ymin = $xyc[1];
            }
        }
        //Add in 10 pixel border to allow for stroke
        $xmax += 10;
        $xmin -= 10;
        $ymax += 10;
        $ymin -= 10;
        //Calculate the canvas size and offset out anything below the minimum value to trim whitespace from top and left
        $xmax -= $xmin;
        $ymax -= $ymin;

        //Iterate through each stroke and each coordinate pair to make the points on the stroke to build each polyline as a string array
        foreach ($xy as $lines => $axis) {
            $polylines[$lines] = '<polyline class="sig" points="';
            foreach ($xy[$lines]['x'] as $point => $val) {
                $x = $xy[$lines]['x'][$point];
                $y = $xy[$lines]['y'][$point];
                $polylines[$lines] .= ($x - $xmin) . ',' . ($y - $ymin) . ' ';
            }
            $polylines[$lines] .= '"/>';
        }
        //Build SVG image string
        $image = '
    <svg id="sig" data-name="sig" xmlns="http://www.w3.org/2000/svg" width="' . $xmax . '" height="' . $ymax . '" viewBox="0 0 ' . $xmax . ' ' . $ymax . '">
      <defs>
        <style>
          .sig {
            fill: none;
            stroke: #000;
            stroke-linecap: round;
            stroke-linejoin: round;
            stroke-width: 4px;
          }
        </style>
      </defs>
      <title>Signature</title>
      <g>
        ';
        foreach ($polylines as $polyline) {
            $image .= $polyline;
        }
        $image .= '
      </g>
    </svg>';

        //If file name is supplied write to file
        if ($filename) {
            try {
                $file = fopen($filename, 'w');
                fwrite($file, $image);
                fclose($file);
                return $filename;
            } catch (Exception $e) {
                return false;
            }
        } else {
            //If file name is not supplied return the SVG image as a string
            return $image;
        }
    } else {
        return "Signature is empty";
    }
}

这篇关于将Topaz Sigweb sigstring转换为Base64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆