폰트없이 바코드출력
페이지 정보
작성자 MintState 댓글 0건 조회 12,732회 작성일 08-10-28 15:37본문
폰트없이 바코드출력
출처는 PHP스쿨입니다.
출처는 PHP스쿨입니다.
<? /* 여기서 ean-13, ean-8, upc-a코드는 맨끝자리 체크비트는 입력을 안한다.... upc-e코드는 체크비트까지 입력을 해야 나오니 이점 참고바람 ean-13 코드 : 바디소프트 8801008010099 ean-8 : 담배와 같은 코드 88006611 upc-a : 016000264595 upc-e : 스니커즈 04010702 # 이미지로 저장될때는 바코드의 값을 이름으로 가진다. 이거 해결하느라고 일주일동안 죽는줄 알았어용 ^^; 마지막으로 .... upc-e 코드의 체크비트 계산법을 아시는 분은 리플좀 달아주세요 ㅡㅡ; 다른코드는 해결했는데 이코드가 문제네용 */ // Check validity of $code /**************************** * EAN-13 Code (13자리) * ****************************/ function Code_Ean13($code) { header ("Content-type: image/jpeg"); $IMG_ROOT = "/images/"; if (strlen($code) != 12) { $im = @ImageCreate (304, 100) or die ("Cannot Initialize new GD image stream"); $bg = ImageColorAllocate ($im, 255, 255, 255); $fg = ImageColorAllocate ($im, 0, 0, 0); ImageString ($im, 5, 3, 10, "Code $code is not valid", $fg); ImageString ($im, 5, 3, 30, "12 digits?", $fg); ImagePng ($im); break; } for ($i = 1; $i <= 12; $i++) { if ((substr($code, $i-1, 1) <= 0) && ((substr($code, $i-1, 1) >= 9))) { $im = @ImageCreate (304, 100) or die ("Cannot Initialize new GD image stream"); $bg = ImageColorAllocate ($im, 255, 255, 255); $fg = ImageColorAllocate ($im, 0, 0, 0); ImageString ($im, 5, 3, 10, "Code $code is not valid", $fg); ImageString ($im, 5, 3, 30, "only digits!", $fg); ImagePng ($im); break; } } // Define bitcode for Numbers $left[0][O] = "0001101"; $left[0][E] = "0100111"; $left[1][O] = "0011001"; $left[1][E] = "0110011"; $left[2][O] = "0010011"; $left[2][E] = "0011011"; $left[3][O] = "0111101"; $left[3][E] = "0100001"; $left[4][O] = "0100011"; $left[4][E] = "0011101"; $left[5][O] = "0110001"; $left[5][E] = "0111001"; $left[6][O] = "0101111"; $left[6][E] = "0000101"; $left[7][O] = "0111011"; $left[7][E] = "0010001"; $left[8][O] = "0110111"; $left[8][E] = "0001001"; $left[9][O] = "0001011"; $left[9][E] = "0010111"; $right[0] = "1110010"; $right[1] = "1100110"; $right[2] = "1101100"; $right[3] = "1000010"; $right[4] = "1011100"; $right[5] = "1001110"; $right[6] = "1010000"; $right[7] = "1000100"; $right[8] = "1001000"; $right[9] = "1110100"; // Calculate Checksum $oddeven = 1; for ($i = 1; $i <= 12; $i++) { $num = substr($code, $i-1, 1); if ($oddeven == 1) { $intsum = $num * $oddeven; $extsum = $extsum + $intsum; $oddeven = 3; } else { $intsum = $num * $oddeven; $extsum = $extsum + $intsum; $oddeven = 1; } } $check = (floor($extsum/10)*10+10) - $extsum; if ($check == 10) { $check = 0; } $code = $code . $check; // Build Array from $code string for ($i = 1; $i <= 13; $i++) { $c[$i] = substr($code, $i-1, 1); } // Set parity switch( $c[1] ) { case 0: $parity = "OOOOO"; break; case 1: $parity = "OEOEE"; break; case 2: $parity = "OEEOE"; break; case 3: $parity = "OEEEO"; break; case 4: $parity = "EOOEE"; break; case 5: $parity = "EEOOEE"; break; case 6: $parity = "EEEOO"; break; case 7: $parity = "EOEOE"; break; case 8: $parity = "EOEEO"; break; case 9: $parity = "EEOEO"; break; } // Start generating bitcode for barcode $barbit = "101"; // Startguard $barbit = $barbit . $left[$c[2]][O]; // 2nd char is always odd for ($i = 3; $i <= 7; $i++) { // generate first 5 digits with parity in bitcode $par = substr($parity, $i - 3, 1); $barbit = $barbit . $left[$c[$i]][$par]; } $barbit = $barbit . "01010"; // Middleguard for ($i = 8; $i <= 13; $i++) { // generate bitcode for 5 digits and 1 checksum $barbit = $barbit . $right[$c[$i]]; } $barbit = $barbit . "101"; // Endguard // Create Image $im = @ImageCreate (304, 100) or die ("Cannot Initialize new GD image stream"); $bg = ImageColorAllocate ($im, 255, 255, 255); $fg = ImageColorAllocate ($im, 0, 0, 0); $start = 14; for ($i = 1; $i <= 95; $i++) { $end = $start + 3; $bit = substr($barbit, $i-1, 1); if ($bit == 0) { Imagefilledrectangle ($im, $start, 0, $end, 100, $bg); } else { Imagefilledrectangle ($im, $start, 0, $end, 100, $fg); } $start = $end; } Imagefilledrectangle ($im, 299, 0, 304, 100, $bg); Imagefilledrectangle ($im, 23, 80, 148, 100, $bg); Imagefilledrectangle ($im, 163, 80, 289, 100, $bg); Imagefilledrectangle ($im, 0, 92, 304, 100, $bg); ImageString ($im, 5, 3, 83, $c[1], $fg); ImageString ($im, 5, 37, 83, "$c[2] $c[3] $c[4] $c[5] $c[6] $c[7]", $fg); ImageString ($im, 5, 177, 83, "$c[8] $c[9] $c[10] $c[11] $c[12] $c[13]", $fg); ImageJpeg($im, $code.".jpg"); copy($code.".jpg", $IMG_ROOT.$code.".jpg"); unlink($code.".jpg"); } /**************************** * EAN-8 Code (8자리) * ****************************/ function Code_Ean8($code) { header ("Content-type: image/jpeg"); $IMG_ROOT = "/images/"; $intsum = 0; $extsum = 0; $oddeven = 3; for ($i = 1; $i <= 7; $i++) { $num = substr($code, $i-1, 1); if ($oddeven == 1) { $intsum = $num * $oddeven; $extsum = $extsum + $intsum; $oddeven = 3; } else { $intsum = $num * $oddeven; $extsum = $extsum + $intsum; $oddeven = 1; } } $check = (floor($extsum/10)*10+10) - $extsum; if ($check == 10) { $check = 0; } $code = $code . $check; for ($i = 1; $i <= 8; $i++) { $c[$i] = substr($code, $i-1, 1); } $barbit = "101"; //START $left[0][O] = "0001101"; $left[1][O] = "0011001"; $left[2][O] = "0010011"; $left[3][O] = "0111101"; $left[4][O] = "0100011"; $left[5][O] = "0110001"; $left[6][O] = "0101111"; $left[7][O] = "0111011"; $left[8][O] = "0110111"; $left[9][O] = "0001011"; $right[0] = "1110010"; $right[1] = "1100110"; $right[2] = "1101100"; $right[3] = "1000010"; $right[4] = "1011100"; $right[5] = "1001110"; $right[6] = "1010000"; $right[7] = "1000100"; $right[8] = "1001000"; $right[9] = "1110100"; for ($i = 1; $i <= 4; $i++) { // 5 Digits $num = substr($code, $i - 1, 1); $barbit = $barbit . $left[$num][O]; } $barbit = $barbit . "01010"; //Mittelteil for ($i = 5; $i <= 8; $i++) { // 6 Digits $num = substr($code, $i - 1, 1); $barbit = $barbit . $right[$num]; } $barbit = $barbit . "101"; $im = @ImageCreate (211, 100) or die ("Cannot Initialize new GD image stream"); $bg = ImageColorAllocate ($im, 255, 255, 255); $fg = ImageColorAllocate ($im, 0, 0, 0); $start = 5; for ($i = 1; $i <= 95; $i++) { $end = $start + 3; $bit = substr($barbit, $i-1, 1); if ($bit == 0) { Imagefilledrectangle ($im, $start, 0, $end, 100, $bg); } else { Imagefilledrectangle ($im, $start, 0, $end, 100, $fg); } $start = $end; } Imagefilledrectangle ($im, 206, 0, 211, 100, $bg); Imagefilledrectangle ($im, 14, 80, 98, 100, $bg); Imagefilledrectangle ($im, 113, 80, 196, 100, $bg); Imagefilledrectangle ($im, 0, 92, 211, 100, $bg); ImageString ($im, 5, 25, 83, "$c[1] $c[2] $c[3] $c[4]", $fg); ImageString ($im, 5, 124, 83, "$c[5] $c[6] $c[7] $c[8]", $fg); ImageJpeg($im, $code.".jpg"); copy($code.".jpg", $IMG_ROOT.$code.".jpg"); unlink($code.".jpg"); } /**************************** * UPC-A Code (12자리) * ****************************/ function Code_Upc_a($code) { header ("Content-type: image/jpeg"); $IMG_ROOT = "/images/"; $save_code = $code; $code = "0" . $code; $intsum = 0; $extsum = 0; $oddeven = 1; for ($i = 1; $i <= 12; $i++) { $num = substr($code, $i-1, 1); if ($oddeven == 1) { $intsum = $num * $oddeven; $extsum = $extsum + $intsum; $oddeven = 3; } else { $intsum = $num * $oddeven; $extsum = $extsum + $intsum; $oddeven = 1; } } $check = (floor($extsum/10)*10+10) - $extsum; if ($check == 10) { $check = 0; } $code = $code . $check; $save_code = $save_code . $check; for ($i = 1; $i <= 13; $i++) { $c[$i] = substr($code, $i-1, 1); } $num = substr($code, 0, 1); // Set parity switch( $num ) { case 0: $parity = "OOOOO"; break; case 1: $parity = "OEOEE"; break; case 2: $parity = "OEEOE"; break; case 3: $parity = "OEEEO"; break; case 4: $parity = "EOOEE"; break; case 5: $parity = "EEOOEE"; break; case 6: $parity = "EEEOO"; break; case 7: $parity = "EOEOE"; break; case 8: $parity = "EOEEO"; break; case 9: $parity = "EEOEO"; break; } $barbit = "101"; //START $left[0][O] = "0001101"; $left[0][E] = "0100111"; $left[1][O] = "0011001"; $left[1][E] = "0110011"; $left[2][O] = "0010011"; $left[2][E] = "0011011"; $left[3][O] = "0111101"; $left[3][E] = "0100001"; $left[4][O] = "0100011"; $left[4][E] = "0011101"; $left[5][O] = "0110001"; $left[5][E] = "0111001"; $left[6][O] = "0101111"; $left[6][E] = "0000101"; $left[7][O] = "0111011"; $left[7][E] = "0010001"; $left[8][O] = "0110111"; $left[8][E] = "0001001"; $left[9][O] = "0001011"; $left[9][E] = "0010111"; $right[0] = "1110010"; $right[1] = "1100110"; $right[2] = "1101100"; $right[3] = "1000010"; $right[4] = "1011100"; $right[5] = "1001110"; $right[6] = "1010000"; $right[7] = "1000100"; $right[8] = "1001000"; $right[9] = "1110100"; $num = substr($code, 1, 1); //Ziffer 2 $barbit = $barbit . $left[$num][O]; for ($i = 3; $i <= 7; $i++) { // 5 Digits $num = substr($code, $i - 1, 1); $par = substr($parity, $i - 3, 1); $barbit = $barbit . $left[$num][$par]; } $barbit = $barbit . "01010"; //Mittelteil for ($i = 8; $i <= 13; $i++) { // 6 Digits $num = substr($code, $i - 1, 1); $barbit = $barbit . $right[$num]; } $barbit = $barbit . "101"; $im = @ImageCreate (313, 100) or die ("Cannot Initialize new GD image stream"); $bg = ImageColorAllocate ($im, 255, 255, 255); $fg = ImageColorAllocate ($im, 0, 0, 0); $start = 14; for ($i = 1; $i <= 95; $i++) { $end = $start + 3; $bit = substr($barbit, $i-1, 1); if ($bit == 0) { Imagefilledrectangle ($im, $start, 0, $end, 100, $bg); } else { Imagefilledrectangle ($im, $start, 0, $end, 100, $fg); } $start = $end; } Imagefilledrectangle ($im, 299, 0, 313, 100, $bg); Imagefilledrectangle ($im, 44, 80, 148, 100, $bg); Imagefilledrectangle ($im, 163, 80, 267, 100, $bg); Imagefilledrectangle ($im, 0, 92, 313, 100, $bg); ImageString ($im, 5, 3, 83, $c[2], $fg); ImageString ($im, 5, 56, 83, "$c[3] $c[4] $c[5] $c[6] $c[7]", $fg); ImageString ($im, 5, 175, 83, "$c[8] $c[9] $c[10] $c[11] $c[12]", $fg); ImageString ($im, 5, 302, 83, $c[13], $fg); ImageJpeg($im, $save_code.".jpg"); copy($save_code.".jpg", $IMG_ROOT.$save_code.".jpg"); unlink($save_code.".jpg"); } /**************************** * UPC-E Code (8자리) * ****************************/ function Code_Upc_e($code) { header ("Content-type: image/jpeg"); $IMG_ROOT = "/images/"; $save_code = $code; $code = $code; $intsum = 0; $extsum = 0; $oddeven = 1; //인쇄할 바코드... for ($i = 1; $i <= 9; $i++) { $c[$i] = substr($code, $i-1, 1); } $code_len = strlen($code) - 1; $num = substr($code, $code_len, 1); // Set parity switch( $num ) { case 0: $parity = "EEEOOO"; break; case 1: $parity = "EEOEOO"; break; case 2: $parity = "EEOOEO"; break; case 3: $parity = "EEOOOE"; break; case 4: $parity = "EOEEOO"; break; case 5: $parity = "EOOEEO"; break; case 6: $parity = "EOOOEE"; break; case 7: $parity = "EOEOEO"; break; case 8: $parity = "EOEOOE"; break; case 9: $parity = "EOOEOE"; break; } $barbit = "101"; //CODE START $left[0][O] = "0001101"; $left[0][E] = "0100111"; $left[1][O] = "0011001"; $left[1][E] = "0110011"; $left[2][O] = "0010011"; $left[2][E] = "0011011"; $left[3][O] = "0111101"; $left[3][E] = "0100001"; $left[4][O] = "0100011"; $left[4][E] = "0011101"; $left[5][O] = "0110001"; $left[5][E] = "0111001"; $left[6][O] = "0101111"; $left[6][E] = "0000101"; $left[7][O] = "0111011"; $left[7][E] = "0010001"; $left[8][O] = "0110111"; $left[8][E] = "0001001"; $left[9][O] = "0001010"; $left[9][E] = "0010111"; for ($i = 2; $i <= 7; $i++) { // 6 Digits $num = substr($code, $i - 1, 1); $par = substr($parity, $i - 2, 1); $barbit = $barbit . $left[$num][$par]; } $barbit = $barbit . "010101"; //Mittelteil $im = @ImageCreate (176, 100) or die ("Cannot Initialize new GD image stream"); $bg = ImageColorAllocate ($im, 255, 255, 255); $fg = ImageColorAllocate ($im, 0, 0, 0); $start = 10; for ($i = 1; $i <= 95; $i++) { $end = $start + 3; $bit = substr($barbit, $i-1, 1); if ($bit == 0) { Imagefilledrectangle ($im, $start, 0, $end, 100, $bg); } else { Imagefilledrectangle ($im, $start, 0, $end, 100, $fg); } $start = $end; } //이미지를 생성( jpg ) 지정한 $IMG_ROOT폴더로 복사 후 현디렉토리에 생성된 이미지를 삭제한다. Imagefilledrectangle ($im, 166, 0, 176, 100, $bg); Imagefilledrectangle ($im, 24, 80, 152, 100, $bg); Imagefilledrectangle ($im, 0, 92, 176, 100, $bg); ImageString ($im, 5, 0, 83, $c[1], $fg); ImageString ($im, 5, 30, 83, "$c[2] $c[3] $c[4] $c[5] $c[6] $c[7]", $fg); ImageString ($im, 5, 166, 83, "$c[8]", $fg); ImageJpeg($im, $save_code.".jpg"); copy($save_code.".jpg", $IMG_ROOT.$save_code.".jpg"); unlink($save_code.".jpg"); } ?>
|
댓글목록
등록된 댓글이 없습니다.