Milon\Barcode\DNS1D::getBarcodeSVG PHP Метод

getBarcodeSVG() публичный Метод

Return a SVG string representation of barcode.
public getBarcodeSVG ( $code, $type, $w = 2, $h = 30, $color = 'black' ) : string
$code (string) code to print
$type (string) type of barcode:
  • C39 : CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.
  • C39+ : CODE 39 with checksum
  • C39E : CODE 39 EXTENDED
  • C39E+ : CODE 39 EXTENDED + CHECKSUM
  • C93 : CODE 93 - USS-93
  • S25 : Standard 2 of 5
  • S25+ : Standard 2 of 5 + CHECKSUM
  • I25 : Interleaved 2 of 5
  • I25+ : Interleaved 2 of 5 + CHECKSUM
  • C128 : CODE 128
  • C128A : CODE 128 A
  • C128B : CODE 128 B
  • C128C : CODE 128 C
  • EAN2 : 2-Digits UPC-Based Extention
  • EAN5 : 5-Digits UPC-Based Extention
  • EAN8 : EAN 8
  • EAN13 : EAN 13
  • UPCA : UPC-A
  • UPCE : UPC-E
  • MSI : MSI (Variation of Plessey code)
  • MSI+ : MSI + CHECKSUM (modulo 11)
  • POSTNET : POSTNET
  • PLANET : PLANET
  • RMS4CC : RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)
  • KIX : KIX (Klant index - Customer index)
  • IMB: Intelligent Mail Barcode - Onecode - USPS-B-3200
  • CODABAR : CODABAR
  • CODE11 : CODE 11
  • PHARMA : PHARMACODE
  • PHARMA2T : PHARMACODE TWO-TRACKS
$w (int) Minimum width of a single bar in user units.
$h (int) Height of barcode in user units.
$color (string) Foreground color (in SVG format) for bar elements (background is transparent).
Результат string SVG code.
    public function getBarcodeSVG($code, $type, $w = 2, $h = 30, $color = 'black')
    {
        if (!$this->store_path) {
            $this->setStorPath(app('config')->get("barcode.store_path"));
        }
        $this->setBarcode($code, $type);
        // replace table for special characters
        $repstr = array("" => '', '&' => '&amp;', '<' => '&lt;', '>' => '&gt;');
        $svg = '<' . '?' . 'xml version="1.0" standalone="no"' . '?' . '>' . "\n";
        $svg .= '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">' . "\n";
        $svg .= '<svg width="' . round($this->barcode_array['maxw'] * $w, 3) . '" height="' . $h . '" version="1.1" xmlns="http://www.w3.org/2000/svg">' . "\n";
        $svg .= "\t" . '<desc>' . strtr($this->barcode_array['code'], $repstr) . '</desc>' . "\n";
        $svg .= "\t" . '<g id="bars" fill="' . $color . '" stroke="none">' . "\n";
        // print bars
        $x = 0;
        foreach ($this->barcode_array['bcode'] as $k => $v) {
            $bw = round($v['w'] * $w, 3);
            $bh = round($v['h'] * $h / $this->barcode_array['maxh'], 3);
            if ($v['t']) {
                $y = round($v['p'] * $h / $this->barcode_array['maxh'], 3);
                // draw a vertical bar
                $svg .= "\t\t" . '<rect x="' . $x . '" y="' . $y . '" width="' . $bw . '" height="' . $bh . '" />' . "\n";
            }
            $x += $bw;
        }
        $svg .= "\t" . '</g>' . "\n";
        $svg .= '</svg>' . "\n";
        return $svg;
    }