$code = strlen($code) % 2 != 0 ? '0' . $code : $code; //Pegando cada número do código for ($i = 0; $i < $n; $i += 2) { $current = $this->interleave(substr($code, $i, 1) . substr($code, $i + 1, 1)); //Está no início? Adiciona o início if ($i == 0) { $current = $this->start_code . $current; } //Está no final? Adiciono o final if ($i == $n - 2) { $current .= $this->end_code; } //Transformando cada número os binários utilizados for ($j = 0; $j < strlen($current); $j++) { //Se for 1, a largura é 3. Se for 0, a largura é 1 $width = substr($current, $j, 1) == 1 ? 3 : 1; //pr($width); $this->addBar($this->current_x, $width, $this->color); //Se a última cor for preta, mudo pra branca $this->color = $this->color == 0 ? 1 : 0; //Adiciona o x atual $this->current_x += $width; } } //Adiciona espaço em branco ao final $this->addBar($this->current_x, 1, $this->color); } } if (isset($_GET['n'])) { Barcode::getImage($_GET['n']); }
public static function generateBarCode($num) { Barcode::getImage($num); }