Instantly share code, notes, and snippets.

Embed
What would you like to do?
Генерирует штрих-код формата CODE 39, Пример использования www.example.com/code39.php?str=21010100745&width=400&height=200
<?
header ("Content-type: image/png");
$code = array();
$code['start'] = '1001011011010';
$code['1'] = '110100101011';
$code['2'] = '101100101011';
$code['3'] = '110110010101';
$code['4'] = '101001101011';
$code['5'] = '110100110101';
$code['6'] = '101100110101';
$code['7'] = '101001011011';
$code['8'] = '110100101101';
$code['9'] = '101100101101';
$code['0'] = '101001101101';
$code['A'] = '110101001011';
$code['B'] = '101101001011';
$code['C'] = '110110100101';
$code['D'] = '101011001011';
$code['E'] = '110101100101';
$code['F'] = '101101100101';
$code['G'] = '101010011011';
$code['H'] = '110101001101';
$code['I'] = '101101001101';
$code['J'] = '101011001101';
$code['K'] = '110101010011';
$code['L'] = '101101010011';
$code['M'] = '110110101001';
$code['N'] = '101011010011';
$code['O'] = '110101101001';
$code['P'] = '101101101001';
$code['Q'] = '101010110011';
$code['R'] = '110101011001';
$code['S'] = '101101011001';
$code['T'] = '101011011001';
$code['U'] = '110010101011';
$code['V'] = '100110101011';
$code['W'] = '110011010101';
$code['X'] = '100101101011';
$code['Y'] = '110010110101';
$code['Z'] = '100110110101';
$code['-'] = '100101011011';
$code['.'] = '110010101101';
$code[' '] = '100110101101';
$code['$'] = '100100100101';
$code['/'] = '100100101001';
$code['+'] = '100101001001';
$code['%'] = '101001001001';
$code['*'] = '100101101101';
$code['stop'] = '0100101101101';
$str = $code['start'];
$val = $_GET['str'];
for ($i = 0; $i <= strlen($val); $i++)
{
$str = $str . $code[$val[$i]] . '0';
}
$str = substr($str, 0, strlen($str)-1);
$str .= $code['stop'];
$padding = 20;
$width = $_GET['width'];
$width_block =round(($width - ($padding*2))/strlen($str),3);
$height = $_GET['height'];
$height_block = $height - $padding*3;
$im = ImageCreate ($width, $height) or die ("Ошибка при создании изображения");
$color_white=ImageColorAllocate ($im, 255, 255, 255);
$color_black=ImageColorAllocate ($im, 0, 0, 0);
for ($i = 0; $i < strlen($str); $i++)
{
if ($str[$i] == "0")
{
$line = ImageFilledRectangle ($im, $padding+$i*$width_block, $padding, $padding+($i+1)*$width_block, $padding+$height_block, $color_white);
}
else
{
$line = ImageFilledRectangle ($im, $padding+$i*$width_block, $padding, $padding+($i+1)*$width_block, $padding+$height_block, $color_black);
}
}
$val = substr($val, 0, 1).'.'.substr($val, 1, 3).'.'.substr($val, 4, 2).'.'.substr($val, 6, 5);
ImageString($im,4,$width/3,$height-$padding*1.5,$val,$color_black);
ImageColorTransparent ($im, $color_white);
ImagePng ($im);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment