PHP
Function upcabarcode ($ code) {$ LW = 2; $ hi = 100; $ lencode = array ('0001101', '0011001 ",' 0010011 ',' 011101 ',' 0100011 ',' 0110001 ',' 0101111 ', '0111011', '0110111', '0001011'); $ reencode = array ('1110010', '110010', '1101100', '1000010', '1010000', '100110', '1010000', '1000100', '1001000', '1110100'); $ ENDS = '101'; $ center = '01010'; / * UPC-a Must BE 11 Digits, We Compute the CHECKSUM. * / IF (Strlen ($ code)! = 11 ) {DIE ("UPC-A Must BE 11 Digits");} / * 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. = $ reencode [$ code [$ x]];} $ bars. = $ ends; / * generate the barode image * / $ img = iM Agecreate ($ LW * 95 30, $ Hi 30); $ fg = imagecolorallocate ($ IMG, 0, 0, 0); $ bg = imagecolorallocate ($ IMG, 255, 255, 255); ImageFilledRectangle ($ IMG, 0, 0, $ LW * 95 30, $ Hi 30, $ BG); $ Shift = 10; for ($ x = 0; $ x
{$ 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);} Imagetring ($ IMG, 4, $ LW * 95 17, $ Hi-5, $ CODE [11], $ FG); / * Output the header and content. * / Head ("content-type: image / png"); imagepng ($ img);} Upcabarcode 12345678901 ');
?>