You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

50 lines
1.4 KiB

  1. <?php
  2. // Including all required classes
  3. require_once('class/BCGFontFile.php');
  4. require_once('class/BCGColor.php');
  5. require_once('class/BCGDrawing.php');
  6. // Including the barcode technology
  7. require_once('class/BCGcode39.barcode.php');
  8. // Loading Font
  9. $font = new BCGFontFile('./font/Arial.ttf', 18);
  10. // Don't forget to sanitize user inputs
  11. $text = isset($_GET['text']) ? $_GET['text'] : 'HELLO';
  12. // The arguments are R, G, B for color.
  13. $color_black = new BCGColor(0, 0, 0);
  14. $color_white = new BCGColor(255, 255, 255);
  15. $drawException = null;
  16. try {
  17. $code = new BCGcode39();
  18. $code->setScale(2); // Resolution
  19. $code->setThickness(30); // Thickness
  20. $code->setForegroundColor($color_black); // Color of bars
  21. $code->setBackgroundColor($color_white); // Color of spaces
  22. $code->setFont($font); // Font (or 0)
  23. $code->parse($text); // Text
  24. } catch(Exception $exception) {
  25. $drawException = $exception;
  26. }
  27. /* Here is the list of the arguments
  28. 1 - Filename (empty : display on screen)
  29. 2 - Background color */
  30. $drawing = new BCGDrawing('', $color_white);
  31. if($drawException) {
  32. $drawing->drawException($drawException);
  33. } else {
  34. $drawing->setBarcode($code);
  35. $drawing->draw();
  36. }
  37. // Header that says it is an image (remove it if you save the barcode to a file)
  38. header('Content-Type: image/png');
  39. header('Content-Disposition: inline; filename="barcode.png"');
  40. // Draw (or save) the image into PNG format.
  41. $drawing->finish(BCGDrawing::IMG_FORMAT_PNG);
  42. ?>