From 22bbdb6f143c0271bda3808eea73f8cc58e02103 Mon Sep 17 00:00:00 2001 From: Bryan Schmersal Date: Thu, 23 Jan 2020 22:28:59 -0500 Subject: [PATCH 1/3] Fix upca command line generation and add an option to specify barcode module width --- barcode/__init__.py | 3 ++- barcode/pybarcode.py | 10 ++++++++-- barcode/upc.py | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/barcode/__init__.py b/barcode/__init__.py index f38cc58..dbe4ffe 100755 --- a/barcode/__init__.py +++ b/barcode/__init__.py @@ -85,7 +85,8 @@ def generate( options = writer_options or {} barcode = get(name, code, writer, options) if pil: - return barcode.render(writer_options, text) + return barcode.render(writer_options, text, + ) if isinstance(output, str): fullname = barcode.save(output, options, text) return fullname diff --git a/barcode/pybarcode.py b/barcode/pybarcode.py index 493f4f5..3a22711 100644 --- a/barcode/pybarcode.py +++ b/barcode/pybarcode.py @@ -48,6 +48,8 @@ def create_barcode(args, parser): ) if args.type != 'SVG': opts = {'format': args.type} + if args.module_width: + opts['module_width'] = args.module_width/100.0 writer = ImageWriter() else: opts = {'compress': args.compress} @@ -105,6 +107,10 @@ def main(): '--text', help='Text to show under the ' 'barcode.' ) + create_parser.add_argument( + '--module_width', help='Unit size for the barcode.', + type=float + ) if ImageWriter is not None: create_parser.add_argument( '-t', '--type', help='Type of output ' @@ -122,10 +128,10 @@ def main(): ) gui_parser.set_defaults(func=open_gui) create_parser.set_defaults( - type='svg', + type='png', compress=False, func=create_barcode, - barcode='code39', + barcode='upca', text=None ) args = parser.parse_args() diff --git a/barcode/upc.py b/barcode/upc.py index a27f71b..595ae8a 100755 --- a/barcode/upc.py +++ b/barcode/upc.py @@ -29,7 +29,7 @@ class UniversalProductCodeA(Barcode): digits = 11 - def __init__(self, upc, writer=None, make_ean=False): + def __init__(self, upc, writer=None, make_ean=False, *args, **kwds): self.ean = make_ean upc = upc[:self.digits] if not upc.isdigit(): From a71de060b9df436e614da4226888d09cef1abe0d Mon Sep 17 00:00:00 2001 From: Bryan Schmersal Date: Thu, 23 Jan 2020 23:13:31 -0500 Subject: [PATCH 2/3] add tiler script --- tile.py | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 tile.py diff --git a/tile.py b/tile.py new file mode 100755 index 0000000..a626c94 --- /dev/null +++ b/tile.py @@ -0,0 +1,62 @@ +#! /usr/bin/env python + +import numpy as np +import cv2 +import os +import sys +import pprint +import glob + +paper_size = (279, 216, 3) +image_size = (paper_size[0] - (2*25.4), paper_size[1] - (2*25.4), paper_size[2]) + +dotspermm = 300/25.4 + +image_size = (int(image_size[0] * dotspermm), int(image_size[1] * dotspermm), image_size[2]) + + +paths = {} +image = None +for path in sorted(glob.glob('outfile_*.png')): + index, size = [int(x) for x in path.replace('outfile_', '').replace('.png', '').split('_')] + if size not in paths: + paths[size] = {} + paths[size][index] = path + +outindex = 0 +for size, v in sorted(paths.items()): + if image is None: + image = 255 * np.ones(image_size, dtype=np.uint8) + yoff = 0 + xoff = 0 + for index, path in sorted(v.items()): + barcode = cv2.imread(path) + right = xoff + barcode.shape[1] + if right > image_size[1]: + xoff = 0 + yoff += barcode.shape[0] + bottom = yoff + barcode.shape[0] + if bottom > image.shape[0]: + cv2.imwrite('labels%03d.png'% outindex, image) + outindex += 1 + ''' + cv2.imshow('image', image) + cv2.waitKey(0) + cv2.destroyAllWindows() + ''' + image = 255 * np.ones(image_size, dtype=np.uint8) + yoff = 0 + xoff = 0 + right = xoff + barcode.shape[1] + if right > image_size[1]: + xoff = 0 + yoff += barcode.shape[0] + bottom = yoff + barcode.shape[0] + if bottom > image.shape[0]: + sys.exit(0) + print yoff, bottom, xoff, right, path, image.shape, barcode.shape + image[yoff:yoff+barcode.shape[0], xoff:xoff+barcode.shape[1]] = barcode + xoff += barcode.shape[1] + + + From b62e2c4f7df4dc644804f08e2a5f11166777203c Mon Sep 17 00:00:00 2001 From: Bryan Schmersal Date: Thu, 23 Jan 2020 23:15:25 -0500 Subject: [PATCH 3/3] Add BN readme --- README_bossanova | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 README_bossanova diff --git a/README_bossanova b/README_bossanova new file mode 100644 index 0000000..d857be7 --- /dev/null +++ b/README_bossanova @@ -0,0 +1,6 @@ +Generate images with something like this: + +for index in {000001..000040}; do for range in 020 030 040 050 060 070 080 090 100 110 120 130 140 150; do python-barcode create "40${index}${range}" outfile_${index}_${range} --module_width ${range}; done; done + +Then run tile.py to generate the sheets to be printed. +