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' => '1011110000100001', |
|
8 |
'BT' => '0', |
|
9 |
'0' => '1010100001111', |
|
10 |
'1' => '1010111100001', |
|
11 |
'2' => '1010000101111', |
|
12 |
'3' => '1111000010101', |
|
13 |
'4' => '1011110100001', |
|
14 |
'5' => '1111010100001', |
|
15 |
'6' => '1000010101111', |
|
16 |
'7' => '1000010111101', |
|
17 |
'8' => '1000011110101', |
|
18 |
'9' => '1111010000101', |
|
19 |
'-' => '1010000111101', |
|
20 |
'$' => '1011110000101', |
|
21 |
':' => '1111010111101111', |
|
22 |
'/' => '1111011110101111', |
|
23 |
'.' => '1111011110111101', |
|
24 |
'+' => '1011110111101111' |
|
25 |
); |
|
26 |
|
|
27 |
function gen_binary($kod) { |
|
28 |
global $code; |
|
29 |
|
|
30 |
$kod = str_split($kod); |
|
31 |
$ret = ''; |
|
32 |
foreach($kod as $key => $val) { |
|
33 |
$ret .= $code[$val].$code['BT']; |
|
34 |
} |
|
35 |
|
|
36 |
return $ret; |
|
37 |
} |
|
38 |
function print_code($kod, $img, $b, $w) { |
|
39 |
$kod = str_split($kod); |
|
40 |
foreach($kod as $val) { |
|
41 |
if($val==1) { |
|
42 |
imageline($img, $now, 0, $now, 40, $b); |
|
43 |
$now++; |
|
44 |
} |
|
45 |
elseif($val==0) { |
|
46 |
$now++; |
|
47 |
} |
|
48 |
} |
|
49 |
} |
|
50 |
|
|
51 |
function kod($kod) { |
|
52 |
global $code; |
|
53 |
$kod = $code['SS'].$code['BT'].gen_binary($kod).$code['SS']; |
|
54 |
|
|
55 |
$i = imagecreate(strlen($kod), 40); |
|
56 |
$w = imagecolorallocate($i, 255, 255, 255); |
|
57 |
$b = imagecolorallocate($i, 0, 0, 0); |
|
58 |
|
|
59 |
print_code($kod, $i, $b, $w); |
|
60 |
|
|
61 |
ob_start(); |
|
62 |
imagegif($i); |
|
63 |
$img = ob_get_contents(); |
|
64 |
ob_end_clean(); |
|
65 |
|
|
66 |
return $img; |
|
67 |
} |
532779
|
68 |
?> |