JavaScript QR Code Reader - can it be done? Or, Remote Service? - php

I'm doing a bit of preliminary research on an upcoming project and I have a quick question that I figure I'll throw up here while I look elsewhere, in case anyone has any experience with this.
The question is simple: is it possible to read a QR code using JavaScript? Is there a remote service to which I can pass a bitmap object from a camera and do it that way? Are there currently any libraries that allow this?
The project is going to be deployed to various mobile devices and we'd like to try to use Appcelerator to make it work. I know Appcelerator does expose the Camera API on its host devices, but whatever we do with it has to be able to parse QR codes. Is this something that can be done?
Thanks in advance!
myk

I bet it's possible, but it would be a challenge. Someone's written an AS3 library for reading QR codes. I'd start by reading up on image manipulation in Canvas.
If you go down the remote API route, Kaywa have an API you may be able to use.

You can use the getUserMedia API to get video from the webcam and you could put it into a canvas element and use the canvas to read the pixels and decode a QR code.
I don't know of a library to decode QR codes but here is one library that can do bar codes.

There's a javascript library already, however the comments are mostly in Japanese and there's no documentation.

Because of memory limits for JavaScript on mobile devices, it's likely to take too long for practical use, if it is possible with purely JS.
I don't know exactly how the Appcelerator API works with external native libraries, but your best bet is to pass the image data to the native code (Objective-C or Java) and then use a lower-level library (like iphone-qrcode) to parse the QR code, then pass the result back to the JS execution context.
This has the added advantage of working offline, which a remote service could not do.

If you want a proof-of-concept, then here it is - a motion tracker written in pure Javascript.
However, support for it is not widespread right now. Only FF and the latest Webkit builds support it afaik.
Just noticed that you wanted this for a mobile device. Then absolutely go with a remote service. It will be really taxing even on the most high end devices assuming they even support it, which I highly doubt.

Related

Flash or JQuery or Other Graph Visualization

I have two basic bar charts and I am currently using XML/SWF Charts which is great but the problem I have is I need to be able to send these graphs via email to the user. As well as display them on the site.
I know sending Flash is a bad idea, I would love to find a way to convert my current graphs to an image, but am pretty certain there is no quick fix without building a work around myself.
Therefore what are the best open source or closed solutions for this problem.
I need to be able to display two graphs dynamically and then email them to users.
Any advice is appreciated.
You may want to check out the "Google Image Chart Api" (not to be confused with the Google Chart API).
http://code.google.com/apis/chart/image/
It allows you to generate numerious different types of charts just from the URL.
For example:
https://chart.googleapis.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World
That URL could also be put into an HTML e-mail.
Alternatively, looking at this stackoverflow quesiton FLASH save frame, to image (tiff, bmp, jpg, gif, png)
If you can modify the flash movie. It appears that you can save frames in AS3 via BitmapData. So you may be able to send the data back to the server for processing (emailing). But I can't vouch for this as I haven't tried it.
jqPlot seems pretty good. Piwik uses it. http://www.jqplot.com/
I would recommend using gRaphael. It is a javascript library for rendering graphs using svg(or vml for IE8 and below). I've personally use it and it is quite good.
This probably won't work for you since you're not running .net, but for anyone else who's looking for resources for generating charts there's the MS Chart controls.

How can you read QR Codes in PHP?

Is there a plain PHP implementation for decoding QR codes?
I have a faux-smartphone. One of those phones that parades as a smartphone but that I can't download any apps for, and I want to create an email service to where I can take a picture of a QR code, MMS it to this email, and the email returns what the QR code contains.
However, the only libraries I've been able to find are in Python (and probably C++), neither of which I can access on my limited hosting environment.
Is there a way to read QR codes using only PHP?
There is only one pure PHP QR code decoder. It's working with GD library, but can use also ImageMagick. This PHP QR code reader is ported from ZXing.
https://github.com/khanamiryan/php-qrcode-detector-decoder
I'm not aware of any pure php decoder. Decoding images like this is pretty processor intensive and doing it in a purely interpreted language is challenging.
zxing (http://code.google.com/p/zxing/) provides a decoder implementation in both Java and C++. In theory, it should be possible to link the C++ library as a php extension, though I don't know anything of the mechanics of that. I've done it for Ruby ...
Moreover, zxing does have an online decoder at http://zxing.org/w/decode.jspx. My thinking is that from PHP you can take the image and post it to the webservice and retrieve the decoded data. I don't know the mechanics of making remote web service calls from PHP and how different hosting environments might limit that, though, but it seems reasonable?
If you have the possibility to use a phpextension, php-zbarcode at https://github.com/mkoppanen/php-zbarcode can read qrcodes. It's a wrapper for ZBar from http://zbar.sourceforge.net, which in turn is a LGPL C library for decoding barcodes.
To decode your QR code you have to upload image of QR code and it will show you text inside that code image.
http://www.phpgang.com/how-to-decode-qr-code_344.html
Very easy to do tutorial I hope it helps.
Here is a good example & you can generate online direct QR code too...
there is also php library to implement QR code in your project.
http://phpqrcode.sourceforge.net/

PHP charting library

I'm looking for a PHP chart library, with a few specific criteria:
I can't use Google charts because, in at least one case, I need to be able to run on a private network with no internet access (ergo no Google).
I need to be able to produce bitmapped images (png, etc). SVG would also be nice, and Flash is acceptable as an extra, but the static bitmapped images are necessary (so a completely Flash chart would be unusable).
Open source preferred but commercial is acceptable.
Take a look at:
JpGraph
pChart
Another suggestion in PHP in addition to the already mentioned:
Topnew SVG Chart 5.5 or bChart - a simple PHP chart for older versions.
Hope this helps someone!
Try this new stuff:
http://www.highcharts.com/ written in javascript
I would recomment Flot - it's a client-side (javascript) charting library, but it does not requite an internet connection (you can host everything on the intranet). If you want a PHP wrapper for it, many frameworks come with it - for example, here's one for QCubed, the framework that I use: http://examples.qcu.be/assets/plugins/QFlot/example/qflot-timeseries.php
Try:
Open Flash Chart
Google Chart API

Create an image of a div?

I was wondering if it's possible to create an image of a div inside a page in php, jquery or javascript? Or even just a screenshot of the entire page (on my own server - not external)..
What I want to do is create an image of a graph (drawn in via jQuery) and pass it onto a PDF, as I can't seem to get the jQuery to display in the pdf..
Because of the security risks, it is not possible to get Javascript to make a screenshot of a web page. This would allow you to steal credit card info, etc... You can use an active X control or something like that, but the client has to knowingly install it in order for things to work.
In PHP, you can create an image and place it on a web page, but again, you cannot see what is on the client's screen. It has to be done on the server before it is sent to the client.
Here is an example of a library you can use to draw a graph in PHP. http://www.aditus.nu/jpgraph/
You might be able to mimic what jQuery is doing in your script but it will take a shift in your applications design.
Take a look at this article:
http://www.developerfusion.com/code/181/capture-screenshot/
It's not client-side code, but you mentioned PHP so maybe server-side code is an option. I don't think you can do it client-side...
How about using a server side graph generator, for example for PHP? Maybe the transition hurts but you'd get a really stable and simple solution.
If you describe what kind of charts you exactly generate and what server side options you have, I'm sure you'll get some specific hints.
Your best bet is to use the GD library on the server to generate the graph as needed. There's no practical way to screencap the browser canvas. Check out this PHP graphing library, it may be what you're looking for:
http://graphpite.sourceforge.net/
If you run into problems where you're doing processing on the client-side that don't exist on the server (i.e.: summing up rows or taking in user settings from cookies), maybe you need to consider passing that data back to the server and letting your hosting handle it (after all, that's why you run a server with lots of RAM and a big CPU, to crunch numbers).
If your javascript draws the graph on a canvas, you can serialize the canvas and then send it to the server using POST.
I don't know if jquery can draw the graph on a canvas, but if the graph is a simple one you could probably code it yourself as canvas has drawing tools already.
Obviously, this only works with browsers supporting canvas.

How to do directed graph drawing in PHP?

I'm looking for a way to draw directed graphs in PHP. (as in http://upload.wikimedia.org/wikipedia/commons/0/08/Directed_acyclic_graph.png). I want it to create an image of the graph just like GD can output an image.
I've googled a lot on this, but I only can find a lot of libraries for drawing graphs in general (with bars etc), not directed graphs.
P.S. I've tried using dot (the linux program) via system(), but unfortunately I have no permission to do that on the server. Also, I have no rights to install PHP extensions and stuff like that on the server, so it should work with normal PHP (ideally just by including a file).
Thanks in advance.
I found a PEAR interface to GraphViz; I have not used it before so can't give you any personal recommendation whether it's good or bad. (but perhaps that doesn't solve your problem since you say you can't install applications)
I'm not aware of any graph visualization implementation in php.
However I suggest you to consider drawing the graph with javascript, for instance with the canviz JS library which works on most browsers (yes, including IE 6 & 7, but not 8 currently).
After a quick Google search, I found graph.php, which in the comments states that it connects nodes through arcs, vice straight lines in the example provided, but may be a good step in the right direction.
Haven't tried it yet, but this looks very promising.
http://www.kylescholz.com/blog/2006/06/using_force_directed_graphs.html
I use php to generate json that is consumed by the d3 force-directed graph system. So the display is all handled client side, all I need to do is make the right json data structures...
-FT

Categories