PHP barcode generation encapsulation class

Source: Internet
Author: User
PHP barcode generation encapsulation class

  1. // Reference the class corresponding to the class folder
  2. Require_once ('class/BCGFontFile. php ');
  3. Require_once ('class/BCGColor. php ');
  4. Require_once ('class/BCGDrawing. php ');
  5. // Code format
  6. Require_once ('class/BCGcode39.barcode. php ');
  7. // Load the font size
  8. $ Font = new BCGFontFile ('./class/font/Arial. ttf', 18 );
  9. // Color bar code
  10. $ Color_black = new BCGColor (0, 0, 0 );
  11. $ Color_white = new BCGColor (255,255,255 );
  12. $ DrawException = null;
  13. Try {
  14. $ Code = new BCGcode39 ();
  15. $ Code-> setScale (2 );
  16. $ Code-> setThickness (30); // The barcode thickness.
  17. $ Code-> setForegroundColor ($ color_black); // barcode color
  18. $ Code-> setBackgroundColor ($ color_white); // blank gap color
  19. $ Code-> setFont ($ font );//
  20. $ Code-> parse ('Hello'); // the data content required by the barcode
  21. } Catch (Exception $ exception ){
  22. $ DrawException = $ exception;
  23. }
  24. // Draw a bar code based on the preceding conditions
  25. $ Drawing = new BCGDrawing ('', $ color_white );
  26. If ($ drawException ){
  27. $ Drawing-> drawException ($ drawException );
  28. } Else {
  29. $ Drawing-> setBarcode ($ code );
  30. $ Drawing-> draw ();
  31. }
  32. // Generate an image in PNG format
  33. Header ('content-Type: image/png ');
  34. $ Drawing-> finish (BCGDrawing: IMG_FORMAT_PNG );
  35. ?>


PHP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.