✏️ 正在编辑: CodigoBarras.php
路径:
/srv/systems_dir/yuppiecred/library/Core/CodigoBarras.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Core_CodigoBarras { protected static $_path; protected static $_numCodebar; private static function getPath($file=null) { return $file ? self::$_path . ltrim($file, ' /') : self::$_path; } private static function setPath($path) { self::$_path = rtrim($path, ' /') . '/'; } public static function gerar($numero, $path) { self::setPath($path); return self::fbarcode($numero); } public static function getNumCodebar() { return self::$_numCodebar; } private static function fbarcode($valor) { $valor = self::formataNumero($valor, 20); self::$_numCodebar = $valor; $fino = 1; $largo = 3; $altura = 50; $barcodes[0] = '00110'; $barcodes[1] = '10001'; $barcodes[2] = '01001'; $barcodes[3] = '11000'; $barcodes[4] = '00101'; $barcodes[5] = '10100'; $barcodes[6] = '01100'; $barcodes[7] = '00011'; $barcodes[8] = '10010'; $barcodes[9] = '01010'; for ($f1 = 9; $f1 >= 0; $f1--) { for ($f2 = 9; $f2 >= 0; $f2--) { $f = ($f1 * 10) + $f2; $texto = ""; for ($i = 1; $i < 6; $i++) { $texto .= substr($barcodes[$f1], ($i - 1), 1) . substr($barcodes[$f2], ($i - 1), 1); } $barcodes[$f] = $texto; } } //Desenho da barra //Guarda inicial $saida = '<img src="' . self::getPath('p.png') . '" width="' . $fino . '" height="' . $altura . '" border="0">' . '<img src="' . self::getPath('b.png') . '" width="' . $fino . '" height="' . $altura . '" border="0">' . '<img src="' . self::getPath('p.png') . '" width="' . $fino . '" height="' . $altura . '" border="0">' . '<img src="' . self::getPath('b.png') . '" width="' . $fino . '" height="' . $altura . '" border="0">'; $texto = $valor; if ((strlen($texto) % 2) <> 0) { $texto = '0' . $texto; } // Draw dos dados while (strlen($texto) > 0) { $i = round(self::esquerda($texto, 2)); $texto = self::direita($texto, strlen($texto) - 2); $f = $barcodes[$i]; for ($i = 1; $i < 11; $i+=2) { if (substr($f, ($i - 1), 1) == '0') { $f1 = $fino; } else { $f1 = $largo; } $saida .= '<img src="' . self::getPath('p.png') . '" width="' . $f1 . '" height="' . $altura . '" border="0">'; if (substr($f, $i, 1) == '0') { $f2 = $fino; } else { $f2 = $largo; } $saida .= '<img src="' . self::getPath('b.png') . '" width="' . $f2 . '" height="' . $altura . '" border="0">'; } } // Draw guarda final $saida .= '<img src="' . self::getPath('p.png') . '" width="' . $largo . '" height="' . $altura . '" border="0">' . '<img src="' . self::getPath('b.png') . '" width="' . $fino . '" height="' . $altura . '" border="0">' . '<img src="' . self::getPath('p.png') . '" width="1" height="' . $altura . '" border="0">'; return $saida; } public static function esquerda($entra, $comp) { return substr($entra, 0, $comp); } public static function direita($entra, $comp) { return substr($entra, strlen($entra) - $comp, $comp); } public static function formataNumero($numero, $tam){ while( strlen($numero) < $tam ){ $numero = "0" . $numero; } return $numero; } }
💾 保存文件
← 返回文件管理器