Advertisement
j0h

mk_Note_Barcodes

j0h
Jul 7th, 2025
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. import barcode
  3. from barcode.writer import ImageWriter
  4.  
  5. # Generate Note barcodes
  6. notes = [
  7.     "A",
  8.     "A#",
  9.     "B",
  10.     "C",
  11.     "C#",
  12.     "D",
  13.     "D",
  14.     "E",
  15.     "E#",
  16.     "F",
  17.     "F#",
  18.     "G"
  19. ]
  20.  
  21. # Define smaller barcode settings
  22. writer_options = {
  23.     'module_width': 0.20,  # default is 0.2
  24.     'module_height': 3.0,  # default is 15.0
  25.     'font_size': 3,        # default is 10
  26.     'text_distance': 4.0,  # space between barcode and text
  27.     'quiet_zone': 2.0,     # whitespace on sides
  28.     'write_text': True     # include text under barcode
  29. }
  30.  
  31. # Use Code128 format
  32. code128 = barcode.get_barcode_class('code128')
  33.  
  34. # Generate and save each barcode
  35. for note in notes:
  36.  
  37.     full_text = f"{note}"
  38.     filename = f"{note}"
  39.     code = code128(full_text, writer=ImageWriter())
  40.     code.save(filename,options=writer_options) # adds the png extension
  41.     #code.save(filename)
  42.     print(f"Saved barcode: {filename}")
  43.  
  44.  
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement