2017-07-12 6 views
1

php htmlを使用してバーコードイメージを縦一直線に表示する方法を教えてください。 1番目と2番目の画像は整理整頓されていないので、誰かが自分のコードを確認できますか?php htmlを使用してバーコードイメージを縦一直線に表示する方法は?

<!DOCTYPE html> 
<html> 
<head> 
    <title></title> 
</head> 
<body> 
<form method="GET" action="Code39.php"> 

</form> 
</body> 
</html> 
<?php 
    ini_set('display_errors',1); 
    error_reporting(E_ALL|E_STRICT); 

    $mcode=1000001; 
    $count=0; 
    while ($count<=20){ 
    $code = isset($_GET['code']) ? $_GET['code'] :$mcode ; 
    $barcode = draw($code); 

    echo "<div style=\"float:left;\">"; 
    echo $mcode."<br>"; 
    echo $barcode."<br>"; 
    echo "</div>"; 

    $count++; 
    $mcode++; 
} 
?> 

enter image description here

あなたが見ることができるように、バーコード画像を整理整頓状に配置されていません。誰かが自分のコードをチェックできますか?

あなたはこのコードを実行しようとする場合は、ここでの完全なコードは、PHPのファイル名はCode39.phpです:本当に

<?php 
    $Code39 = array(
'0'=>'111221211', 
'1'=>'211211112', 
'2'=>'112211112', 
'3'=>'212211111', 
'4'=>'111221112', 
'5'=>'211221111', 
'6'=>'112221111', 
'7'=>'111211212', 
'8'=>'211211211', 
'9'=>'112211211', 
'A'=>'211112112', 
'B'=>'112112112', 
'C'=>'212112111', 
'D'=>'111122112', 
'E'=>'211122111', 
'F'=>'112122111', 
'G'=>'111112212', 
'H'=>'211112211', 
'I'=>'112112211', 
'J'=>'111122211', 
'K'=>'211111122', 
'L'=>'112111122', 
'M'=>'212111121', 
'N'=>'111121122', 
'O'=>'211121121', 
'P'=>'112121121', 
'Q'=>'111111222', 
'R'=>'211111221', 
'S'=>'112111221', 
'T'=>'111121221', 
'U'=>'221111112', 
'V'=>'122111112', 
'W'=>'222111111', 
'X'=>'121121112', 
'Y'=>'221121111', 
'Z'=>'122121111', 
'-'=>'121111212', 
'.'=>'221111211', 
' '=>'122111211', 
'$'=>'121212111', 
'/'=>'121211121', 
'+'=>'121112121', 
'%'=>'111212121', 
'*'=>'121121211'); 

    $unit='px';//Unit 
    $bw=2;//bar width 
    $height=50*$bw;// px 
    $fs=8*$bw;//Font size 
    $yt=45*$bw; 
    $dx=3*$bw; 
    $x=4*$bw; 
    $y=2.5*$bw; 
    $bl=35*$bw; 
    function checksum($string) 
    { 
     $checksum = 0; 
     $length = strlen($string); 
     $charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%'; 

     for($i=0; $i < $length; ++$i) 
     { 
      $checksum += strpos($charset, $string[$i]); 
     } 

     return substr($charset, ($checksum % 43), 1); 
    } 
    function draw($str,$checksum=false){ 
     global $unit,$x,$Code39,$height,$bw; 
     $str=strtoupper($str); 
     if ($checksum) { 
      $str=$str.checksum($str); 
     } 
     $str='*'.$str.'*'; 
     $long=(strlen($str)+100)*100; 
     $width=$bw*$long; 
     $text=str_split($str); 
     $img=''; 
     $img.= "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"; 
     $img.= "<svg width='$width$unit' height='$height$unit' version='1.1' xmlns='http://www.w3.org/2000/svg'>\n"; 


     foreach($text as $char){ 
      $img.=drawsymbol($char); 
     } 

     $img.='</svg>'; 

     return $img; 
    } 

    function drawsymbol($char){ 
     global $unit,$Code39,$x,$y,$dx,$bw,$fs,$dx,$yt,$bl; 
     $x+=$bw; 
     $img=''; 
     $img.= '<desc>'.htmlspecialchars($char)."</desc>\n"; 
     $xt=$x+$dx; 
     $img.= "<text x='$xt$unit' y='$yt$unit' font-family='Arial' font-size='$fs'>$char</text>\n"; 
     $val =str_split($Code39[$char]); 
     $len=9; 
     for ($i=0; $i<$len; $i++){ 
      $num=(int)$val[$i]; 
      $w=$bw*$num; 
      if(!($i % 2)){ 
       $img.= "<rect x='$x$unit' y='$y$unit' width='$w$unit' height='$bl$unit' fill='black' stroke-width='0' />\n"; 
      } 
      $x += $w; 
     } 
     return $img; 
    } 

?> 
<!DOCTYPE html> 
<html> 
<head> 
    <title></title> 
</head> 
<body> 
<form method="GET" action="Code39.php"> 

</form> 
</body> 
</html> 
<?php 
    ini_set('display_errors',1); 
    error_reporting(E_ALL|E_STRICT); 

    $mcode=1000001; 
    $count=0; 
    while ($count<=20){ 
    $code = isset($_GET['code']) ? $_GET['code'] :$mcode ; 
    $barcode = draw($code); 

    echo "<div style=\"float:left;\">"; 
    echo $mcode."<br>"; 
    echo $barcode."<br>"; 
    echo "</div>"; 

    $count++; 
    $mcode++; 
} 

?> 

答えて

0

ないPHP-質問が、これ試してみてください。

while ($count<=20){ 
    $code = isset($_GET['code']) ? $_GET['code'] :$mcode ; 
    $barcode = draw($code); 

    echo "<div style=\"float:left;\">"; 
    echo $mcode."<br>"; 
    echo $barcode."<br>"; 
    echo "</div>"; 

    $count++; 
    $mcode++; 
} 
+0

結果はまだ同じ@trpxで、画像はまだ私が投稿したものと同じです。他の方法がありますか? –

+0

コードもありがとう、あなたのコードも私を助けます。ありがとうございました :) –

0

は、このコードに私の友人John_Betongにありがとう:

<?php 
    $Code39 = array(
'0'=>'111221211', 
'1'=>'211211112', 
'2'=>'112211112', 
'3'=>'212211111', 
'4'=>'111221112', 
'5'=>'211221111', 
'6'=>'112221111', 
'7'=>'111211212', 
'8'=>'211211211', 
'9'=>'112211211', 
'A'=>'211112112', 
'B'=>'112112112', 
'C'=>'212112111', 
'D'=>'111122112', 
'E'=>'211122111', 
'F'=>'112122111', 
'G'=>'111112212', 
'H'=>'211112211', 
'I'=>'112112211', 
'J'=>'111122211', 
'K'=>'211111122', 
'L'=>'112111122', 
'M'=>'212111121', 
'N'=>'111121122', 
'O'=>'211121121', 
'P'=>'112121121', 
'Q'=>'111111222', 
'R'=>'211111221', 
'S'=>'112111221', 
'T'=>'111121221', 
'U'=>'221111112', 
'V'=>'122111112', 
'W'=>'222111111', 
'X'=>'121121112', 
'Y'=>'221121111', 
'Z'=>'122121111', 
'-'=>'121111212', 
'.'=>'221111211', 
' '=>'122111211', 
'$'=>'121212111', 
'/'=>'121211121', 
'+'=>'121112121', 
'%'=>'111212121', 
'*'=>'121121211'); 

    $unit='px';//Unit 
    $bw=2;//bar width 
    $height=50*$bw;// px 
    $fs=8*$bw;//Font size 
    $yt=45*$bw; 
    $dx=3*$bw; 
    $x=4*$bw; 
    $y=2.5*$bw; 
    $bl=35*$bw; 
    function checksum($string) 
    { 
     $checksum = 0; 
     $length = strlen($string); 
     $charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%'; 

     for($i=0; $i < $length; ++$i) 
     { 
      $checksum += strpos($charset, $string[$i]); 
     } 

     return substr($charset, ($checksum % 43), 1); 
    } 
    function draw($str, $checksum=false) 
{ 
    global $unit, $x, $Code39, $height, $bw; 
    $OLD_X = $x; 

    $str = strtoupper((string) $str); 
    if ($checksum) 
    { 
    $str = $str .checksum($str); 
    } 
    $str = '*' .$str .'*'; 
    $long = (strlen($str)+100)*100; 
    $width = $bw*$long; 
    $text = str_split($str); 
    $img = ''; 
    if(0): 
    $img .= "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"; 
    endif; 

    $img .= '<div style="float:left; padding:1em; background-color:white; text-align:left;">' ."\n\n\t"; 
    $width = '600'; 
    // $img .= "<svg width='$width$unit' height='$height$unit' version='1.1' xmlns='http://www.w3.org/2000/svg' >"; // \n 
    // viewpath='0 0 $width $height' 
    $img .= "<svg width='$width$unit' height='$height$unit' >"; // \n 

    foreach($text as $char) 
    { 
    $img .= drawsymbol($char); 
    }//$OLD_X 
    $img .= '</svg>'; 
    $img .= "\n\n</div><p><br><br><br></p>\n\n"; 

// ESSENTIAL TO RESET GLOBAL $x value 
    $x = $OLD_X;  

    return $img; 
} 

    function drawsymbol($char){ 
     global $unit,$Code39,$x,$y,$dx,$bw,$fs,$dx,$yt,$bl; 
     $x+=$bw; 
     $img=''; 
     $img.= '<desc>'.htmlspecialchars($char)."</desc>\n"; 
     $xt=$x+$dx; 
     $img.= "<text x='$xt$unit' y='$yt$unit' font-family='Arial' font-size='$fs'>$char</text>\n"; 
     $val =str_split($Code39[$char]); 
     $len=9; 
     for ($i=0; $i<$len; $i++){ 
      $num=(int)$val[$i]; 
      $w=$bw*$num; 
      if(!($i % 2)){ 
       $img.= "<rect x='$x$unit' y='$y$unit' width='$w$unit' height='$bl$unit' fill='black' stroke-width='0' />\n"; 
      } 
      $x += $w; 
     } 
     return $img; 
    } 

?> 
<!DOCTYPE html> 
<html> 
<head> 
    <title></title> 
</head> 
<body> 
<form method="GET" action="Code39.php"> 

</form> 
</body> 
</html> 
<?php 
    ini_set('display_errors',1); 
    error_reporting(E_ALL|E_STRICT); 

    $mcode=1000001; 
    $count=0; 
    while ($count<=20){ 
    $code = isset($_GET['code']) ? $_GET['code'] :$mcode ; 
    $barcode = draw($code); 

    echo "<div style=\"float:left;\">"; 
    echo $mcode."<br>"; 
    echo $barcode; 
    //echo "</div>"; 

    $count++; 
    $mcode++; 
} 

?> 

enter image description here

関連する問題