commit | author | age
|
175a52
|
1 |
<?php |
JK |
2 |
if(!extension_loaded('gd')) { |
|
3 |
error::add('Brak rozszerzenia GD/GD2. Generowanie kodów kreskowych jest niemożliwe.'); |
|
4 |
} |
|
5 |
|
|
6 |
$code = array( |
|
7 |
'SS' => '100101101101', |
|
8 |
'BT' => '0', |
|
9 |
'0' => '101001101101', |
|
10 |
'1' => '110100101011', |
|
11 |
'2' => '101100101011', |
|
12 |
'3' => '110110010101', |
|
13 |
'4' => '101001101011', |
|
14 |
'5' => '110100110101', |
|
15 |
'6' => '101100110101', |
|
16 |
'7' => '101001011011', |
|
17 |
'8' => '110100101101', |
|
18 |
'9' => '101100101101', |
|
19 |
'A' => '110101001011', |
|
20 |
'B' => '101101001011', |
|
21 |
'C' => '110110100101', |
|
22 |
'D' => '101011001011', |
|
23 |
'E' => '110101100101', |
|
24 |
'F' => '101101100101', |
|
25 |
'G' => '101010011011', |
|
26 |
'H' => '110101001101', |
|
27 |
'I' => '101101001101', |
|
28 |
'J' => '101011001101', |
|
29 |
'K' => '110101010011', |
|
30 |
'L' => '101101010011', |
|
31 |
'M' => '110110101001', |
|
32 |
'N' => '101011010011', |
|
33 |
'O' => '110101101001', |
|
34 |
'P' => '101101101001', |
|
35 |
'Q' => '101010110011', |
|
36 |
'R' => '110101011001', |
|
37 |
'S' => '101101011001', |
|
38 |
'T' => '101011011001', |
|
39 |
'U' => '110010101011', |
|
40 |
'V' => '100110101011', |
|
41 |
'W' => '110011010101', |
|
42 |
'X' => '100101101011', |
|
43 |
'Y' => '110010110101', |
|
44 |
'Z' => '100110110101', |
|
45 |
'-' => '100101011011', |
|
46 |
'.' => '110010101101', |
|
47 |
' ' => '100110101101', |
|
48 |
'$' => '100100100101', |
|
49 |
'/' => '100100101001', |
|
50 |
'+' => '100101001001', |
|
51 |
'%' => '101001001001', |
|
52 |
); |
|
53 |
|
|
54 |
function gen_binary($kod) { |
|
55 |
global $code; |
|
56 |
|
|
57 |
$kod = str_split($kod); |
|
58 |
$ret = ''; |
|
59 |
foreach($kod as $key => $val) { |
|
60 |
$ret .= $code[$val].$code['BT']; |
|
61 |
} |
|
62 |
|
|
63 |
return $ret; |
|
64 |
} |
|
65 |
function print_code($kod, $img, $b, $w) { |
|
66 |
$kod = str_split($kod); |
|
67 |
foreach($kod as $val) { |
|
68 |
if($val==1) { |
|
69 |
imageline($img, $now, 0, $now, 40, $b); |
|
70 |
$now++; |
|
71 |
} |
|
72 |
elseif($val==0) { |
|
73 |
$now++; |
|
74 |
} |
|
75 |
} |
|
76 |
} |
|
77 |
|
|
78 |
function kod($kod) { |
|
79 |
global $code; |
|
80 |
|
|
81 |
if(trim($kod, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $')!='') { |
|
82 |
error::add('Znaki inne niż cyfry, litery, pauza, kropka, spacja, ukośnik'); |
|
83 |
} |
|
84 |
|
|
85 |
$kod = $code['SS'].$code['BT'].gen_binary($kod).$code['SS']; |
|
86 |
|
|
87 |
$i = imagecreate(strlen($kod), 40); |
|
88 |
$w = imagecolorallocate($i, 255, 255, 255); |
|
89 |
$b = imagecolorallocate($i, 0, 0, 0); |
|
90 |
|
|
91 |
print_code($kod, $i, $b, $w); |
|
92 |
|
|
93 |
ob_start(); |
|
94 |
imagegif($i); |
|
95 |
$img = ob_get_contents(); |
|
96 |
ob_end_clean(); |
|
97 |
|
|
98 |
return $img; |
|
99 |
} |
532779
|
100 |
?> |