Php generates a barcode
<? Php
Function UPCAbarcode ($ code ){
$ Lw = 2; $ hi = 100;
$ Lencode = array ('20140901', '20160901', '20160901', '20160301', '20160301 ',
'123', '123', '123', '123', '123 ');
$ Rencode = array ('20140901', '20160901', '20160901', '20160301', '20160301 ',
'123', '123', '123', '123', '123 ');
$ Ends = '20180101'; $ center = '20180101 ';
/* 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. = $ Rencode [$ code [$ x];
}
$ Bars. = $ ends;
/* Generate the Barcode Image */
$ Img = ImageCreate ($ 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 <strlen ($ bars); $ x ++ ){
If ($ x <10) | ($ x >=45 & $ x <50) | ($ x >=85) {$ sh = 10 ;} else {$ sh = 0 ;}
If ($ bars [$ x] = '1') {$ 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 + 17, $ hi-5, $ code [11], $ fg );
/* Output the Header and Content .*/
Header ("Content-Type: image/png ");
ImagePNG ($ img );
}
UPCAbarcode ('20140901 ');
?>