Closed krazyjakee closed 12 years ago
Hey Daniel, can you have a look at this merge if you get a chance?
I see tests are part of the package, which is awesome.
We have a guy at work who does PHP. I will kick it to him. He has his plate full now. Should be done with review in a couple of days.
@krazyjakee If you are doing this for Willow Systems merchant, let me know the Merchant ID. The priority on review will jump to "immediate"
Make note that a lot of the code is not converted because honestly I can't see how I could do it in php, but maybe someone with more experience could. It really is just a skeleton with some functions converted and the unknowns commented out.
I am mainly seeking to convert from base30 to bitmap so if it's just those parts you could help with I would appreciate it.
I am not with willow systems so I understand if there is not a rush.
Pending full, "pure" PHP solution, here are some pointers for getting from base30 to some sort of PNG quickly:
In all cases, getting from base30 to bitmap is a three-step process:
In case of .Net solution the steps are:
In case of PHP, a "similar" solution would be:
In light of a great deal of coding to get #2 and #1 solid, could I offer alternatives?
If you like getting "base30" to server, and rendering speed is not an issue, load data into PhantomJS on the server, use import base30 into jSignature, export svg, put SVG into separate PhantomJS window and scrape it. You get your PNG in one step.
If you cannot run PhantomJS on your server, but it has ImageMagic / GraphicsMagic and you have execute rights, just:
gm.exe convert signature.svg -scale 200x200 -render signature.png
and just use / serve the PNG by path.If the situation is like above, but you cannot execute commands from PHP, but can have 'imagick' do step #2 immediately above but against PHP's imagick extension like so http://stackoverflow.com/a/4809562/366864
If your server does not allow imagic, calls to system (to GraphicsMagic or ImageMagic) or install of PhantomJS, either:
I'm a little confused, have I misread the issue entirely? I didn't know jsignature could pass the full png data as I was only using the example on the jsignature website.
It seems if you want to go from jsignature to a png file on the server with php, you merely have to do this... client
$('#signature').jSignature("getData");
server
$signature = base64_decode(str_replace("data:image/png;base64,","",$_POST['signature']));
file_put_contents('test.png',$signature);
Am I missing something?
@krazyjakee
Re: "Am I missing something?"
See "Data Import / Export (and Plugins)" and "Choosing the export / storage format" chapters here: http://willowsystems.github.com/jSignature/#/about/ for the parts that are missing :)
Summary: if you can handle vector (base30 or SVG) on the server, please, use vector. If not, and you understand the issues of that, use bitmap export.
The port from .Net examples was a bit convoluted (because .Net is convoluted) It was easier to start from scratch and use JavaScript base30-to-Native, Native-to-SVG code as example.
See 'tests' folder for usage. There is an example of rendering SVG to PNG there (last test).
I do NOT recommend this PHP NativeToSVG renderer if you need very high quality SVG. The vectors are converted into simple lines. The curve-smoothing logic that is in JavaScript or in .Net versions of NativeToSVG converters is NOT present in this PHP version.
In other words, this NativeToSVG renderer produces less pretty signatures than the alternatives, but is functional otherwise.
By the way. Test file is in PHPUnit format.
Needs a keener eye then mine, and then some testing.