PHP barcode generation encapsulation class
- // Reference the class corresponding to the class folder
- Require_once ('class/BCGFontFile. php ');
- Require_once ('class/BCGColor. php ');
- Require_once ('class/BCGDrawing. php ');
-
- // Code format
- Require_once ('class/BCGcode39.barcode. php ');
-
- // Load the font size
- $ Font = new BCGFontFile ('./class/font/Arial. ttf', 18 );
-
- // Color bar code
- $ Color_black = new BCGColor (0, 0, 0 );
- $ Color_white = new BCGColor (255,255,255 );
-
- $ DrawException = null;
- Try {
- $ Code = new BCGcode39 ();
- $ Code-> setScale (2 );
- $ Code-> setThickness (30); // The barcode thickness.
- $ Code-> setForegroundColor ($ color_black); // barcode color
- $ Code-> setBackgroundColor ($ color_white); // blank gap color
- $ Code-> setFont ($ font );//
- $ Code-> parse ('Hello'); // the data content required by the barcode
- } Catch (Exception $ exception ){
- $ DrawException = $ exception;
- }
-
- // Draw a bar code based on the preceding conditions
- $ Drawing = new BCGDrawing ('', $ color_white );
- If ($ drawException ){
- $ Drawing-> drawException ($ drawException );
- } Else {
- $ Drawing-> setBarcode ($ code );
- $ Drawing-> draw ();
- }
-
- // Generate an image in PNG format
- Header ('content-Type: image/png ');
-
-
- $ Drawing-> finish (BCGDrawing: IMG_FORMAT_PNG );
- ?>
|
PHP