>  기사  >  백엔드 개발  >  PHP는 바코드 사진을 생성합니다

PHP는 바코드 사진을 생성합니다

墨辰丷
墨辰丷원래의
2018-05-18 09:27:511242검색

이 글은 주로 PHP에서 바코드 사진을 생성하는 자세한 예에 대한 정보를 소개합니다. 도움이 필요한 친구들은

PHP에서 바코드 사진을 생성하는 자세한 예

를 참조하세요. 바코드를 작성해야 합니다. 바코드 이미지를 생성하려면 PHP를 사용하세요. 프로젝트의 루트 디렉터리에 테스트 파일을 만들고 실행해 보세요. 기타), 실제 프로젝트에서는 다음 코드를 공용 클래스 파일 아래의 함수로 캡슐화한 후 호출할 수 있습니다.


class testinfo{
  function UPCAbarcode($code) {
    $trans_code = $code;
    $lw = 2.2; $hi = 40;
    $Lencode = array('0001101','0011001','0010011','0111101','0100011',
        '0110001','0101111','0111011','0110111','0001011');
    $Rencode = array('1110010','1100110','1101100','1000010','1011100',
        '1001110','1010000','1000100','1001000','1110100');
    $ends = '101'; $center = '01010';
    /* Compute the EAN-13 Checksum digit */
    $ncode = '0'.$code;
    $even = 0; $odd = 0;
    for ($x=0;$x<12;$x++) {
      if ($x % 2) {
        $odd += $ncode[$x];
      } else { $even += $ncode[$x];
      }
    }
    $code.=(10 - (($odd * 3 + $even) % 10)) % 10;
    /* Create the bar encoding using a binary string */
    $bars=$ends;
    $bars.=$Lencode[$code[0]];
    
    for($x=1;$x<6;$x++) {
      $bars.=$Lencode[$code[$x]];
    }
    $bars.=$center;
    for($x=6;$x<12;$x++) {
      $bars.=$Rencode[$code[$x]];
    }
    $bars.=$ends;
    /* Generate the Barcode Image */
    $img = ImageCreate($lw*75+30,$hi-3);  // 95
    $fg = ImageColorAllocate($img, 0, 0, 0);
    $bg = ImageColorAllocate($img, 255, 255, 255);
    ImageFilledRectangle($img, 0, 0, $lw*75+30, $hi+30, $bg);
    $shift=10;
    for ($x=0;$x<strlen($bars);$x++) {
      if (($x<0) || ($x>=45 && $x<46) || ($x >=85)) {
        $sh=10;
      } else { $sh=0;
      }
      if ($bars[$x] == &#39;1&#39;) {
        $color = $fg;
      } else { $color = $bg;
      }
      ImageFilledRectangle($img, ($x*$lw)+15,5,($x+1)*$lw+14,$hi+5+$sh,$color);
    }
    /* Add the Human Readable Label */
    ImageString($img,4,5,$hi-5,$code[0],$fg);
    for ($x=0;$x<5;$x++) {
      ImageString($img,5,$lw*(13+$x*6)+15,$hi+5,$code[$x+1],$fg);
      ImageString($img,5,$lw*(53+$x*6)+15,$hi+5,$code[$x+6],$fg);
    }
    ImageString($img,4,$lw*95-7,$hi,$code[11],$fg);
    /* Output the Header and Content. */
    header("Content-Type: image/png");
    ImagePNG($img);
  }
//}
echo UPCAbarcode(&#39;201212070099&#39;);


관련 추천:

vue.js 바코드 생성 방법

php는 code128 바코드 예제 공유 생성

PHP는 바코드 예제 생성

위 내용은 PHP는 바코드 사진을 생성합니다의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.