-
Notifications
You must be signed in to change notification settings - Fork 0
/
qr.php
66 lines (53 loc) · 1.44 KB
/
qr.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
*
* @copyright 2010-2011 izend.org
* @version 1
* @link http://www.izend.org
*/
require_once 'sendhttp.php';
//echo qrencode("hello");
$test = qrdecode("http://luvino.ca/Welcome.jpg", $filetype='image/png');
$start =strpos($test,'Raw text</td><td><pre style="margin:0">');
if ($start !== false) {
$end =strpos($test,'</pre></td></tr><tr><td>Raw bytes');
echo substr($test,$start+39,$end-$start-39);
}
echo "done";
function qrencode($s, $size=100, $quality='M') {
$url = 'http://chart.googleapis.com/chart';
$args = array(
'cht' => 'qr',
'chf' => 'bg,s,ffffff',
'chs' => "${size}x${size}",
'chld' => "${quality}|0",
'chl' => $s,
);
$response=sendget($url, $args);
if (!$response or $response[0] != 200) {
return false;
}
return $response[2];
}
function qrdecode($file, $filetype='image/png') {
$url = 'http://zxing.org/w/decode';
$args = array(
'full' => 'true',
);
$files=array('f' => array('name' => basename($file), 'tmp_name' => $file, 'type' => $filetype));
$response=sendpost($url, $args, $files, false); // DON'T encode data in base64
if (!$response or $response[0] != 200) {
return false;
}
if (preg_match('#<html>.*</html>#', $response[2])) {
return false;
}
return ($response[2]);
}
function data_uri($mime)
{
$base64 = base64_encode(qrencode("hello"));
return ('data:' . $mime . ';base64,' . $base64);
}
?>
<img src="<?php echo data_uri('image/png'); ?>" alt="An elephant" />