def ean13(payload): if args.verbose: logging.getLogger("ean13").setLevel(logging.DEBUG) logging.getLogger("ean13").addHandler(logging.StreamHandler(sys.stdout)) encoded = DataMatrixEncoder(payload) encoded.save(args.outfile)
def datamatrix(data, cellsize=2, with_border=False): """Return a datamatrix's image data. Powered by the Python library ``qrcode``. See this library's documentation for more details. Parameters ---------- data Data to be encoded in the datamatrix cellsize size of the picture in inches (?) with_border If false, there will be no border or margin to the datamatrix image. Returns ------- image_base64_data A string ``data:image/png;base64,xxxxxxxxx`` which you can provide as a "src" parameter to a ``<img/>`` tag. Examples: --------- >>> data = datamatrix('EGF') >>> html_data = '<img src="%s"/>' % data """ encoder = DataMatrixEncoder(data) img_data = encoder.get_imagedata(cellsize=cellsize) img = Image.open(BytesIO(img_data)) if not with_border: img = img.crop(ImageOps.invert(img).getbbox()) return pil_to_html_imgdata(img)
def ean13(payload): if args.verbose: logging.getLogger("ean13").setLevel(logging.DEBUG) logging.getLogger("ean13").addHandler(logging.StreamHandler( sys.stdout)) encoded = DataMatrixEncoder(payload) encoded.save(args.outfile)
def save(self, fn=None): """Save the SVG-file. Parameters ---------- fn Optional filename """ # Currently all other parameters are set in __init__() if fn is not None: self._fn = fn # todo check if ... in self.cpt_tspan.keys(): self.cpt_tspan['title'] = self.content.title self.cpt_tspan['value'] = self.content.value self.cpt_tspan['package'] = self.content.package self.cpt_tspan['tolerance'] = self.content.tolerance self.cpt_tspan[ 'temperature_coefficient'] = self.content.temperature_coefficient self.cpt_tspan['power'] = self.content.power # self.fn is set after this point # todo: think about better solution for self._fn (explicit is better than implicit) super(smd_container, self).save_frame(fn) self._fn_cut = super(smd_container, self)._fn_sub_str(self._fn, '_cut') # save data matrix code with unique id (python3 solution) fn, fext = os.path.splitext(self._fn) fn_qr = fn + '_qr' + '.png' uuid_str = str(uuid.uuid4()) uuid_str = uuid_str.replace('-', '') # remove '-' from uuid uuid_str = uuid_str.lower() # make uuid lower case uuid_str = uuid_str[0:12] # first 12 bytes of uuid encoder = DataMatrixEncoder(uuid_str) encoder.save(fn_qr) if 'matrix' in self.cpt_rect.keys(): self.cpt_rect['matrix'] = fn_qr # save layers for group in self.layer.tmpl_lr.keys(): if group == 'smd_container_cut': super(smd_container, self).save_layers(self._fn_cut, self._fn, group='smd_container_cut') else: super(smd_container, self).save_layers(group=group) # save substitutes super(smd_container, self).save_substitutes()
def draw_datamatrix(self, text, x, y, size, anchor="C"): e_datamatrix = DataMatrixEncoder(text) img = ImageReader(io.BytesIO(e_datamatrix.get_imagedata())) _x, _y = x - size / 2, y - size / 2 if "N" in str(anchor).upper(): _y = y - size if "S" in str(anchor).upper(): _y = y if "E" in str(anchor).upper(): _x = x - size if "W" in str(anchor).upper(): _x = x self.c.drawImage(img, _x, _y, *[size] * 2)
def generate(DMMessage, DMimagename): DM = DataMatrixEncoder(str(DMMessage)) #Create datamatrix dirname = os.path.dirname(__file__) DMimagepath = os.path.join(dirname, "matrix_image_temp\\" + DMimagename + '.png') DM.save(DMimagepath) return DMimagepath
def createLabel(ship_date, current_date): encoder = DataMatrixEncoder('This is a DataMatrix.') encoder.save('./datamatrix_test.png') validate_date(ship_date) print("This shipment scheduled for: ", ship_date) print(encoder.get_ascii()) print("Above is the shipping label") print("Label was printed on: ", current_date)
def gen_bar(self, some, name): data = some.strip('\n').strip('\r') if len(data) > 34: self.print('Error: Record has wrong size!') return encoder = DataMatrixEncoder(data) filename = '{0}{1}{2}.png'.format(self.target_path, os.path.sep, name) self.print('Writing %s' % filename) encoder.save(filename) self.done += 1
def test_encode_decode(self): """Test that dmtxwrite can decode this library's output to the correct string""" for string in MatrixTest.test_strings: encoder = DataMatrixEncoder(string) encoder.save("datamatrix-test.png") if not dmtxread_path: print("dmtxread is not installed or cannot be found - Debian package libdmtx-utils") else: fin = os.popen("sh -c '%s datamatrix-test.png'" % dmtxread_path) self.assertEqual(fin.readline(), string)
def test_encode_decode(self): """Test that dmtxwrite can decode this library's output to the correct string""" for string in MatrixTest.test_strings: encoder = DataMatrixEncoder(string) encoder.save("datamatrix-test.png") if not (os.path.exists(os.path.join('/usr/bin', dmtxread_path)) or os.path.exists(os.path.join('/usr/local/bin', dmtxread_path))): print("%r does not exist, skipping decoding tests" % dmtxread_path) else: fin = os.popen("sh -c '%s datamatrix-test.png'" % dmtxread_path) self.assertEqual(fin.readline(), string)
def test_encode_decode(self): """Test that dmtxwrite can decode this library's output to the correct string""" for string in MatrixTest.test_strings: encoder = DataMatrixEncoder(string) encoder.save("datamatrix-test.png") if not dmtxread_path: print( "dmtxread is not installed or cannot be found - Debian package libdmtx-utils" ) else: fin = os.popen("sh -c '%s datamatrix-test.png'" % dmtxread_path) self.assertEqual(fin.readline(), string)
def barcode(self, barcode_type, value, width=600, height=100, humanreadable=0): if barcode_type != 'datamatrix': return super(ReportAction, self).barcode(barcode_type, value, width=width, height=height, humanreadable=humanreadable) else: try: barcode = DataMatrixEncoder(value) return barcode.get_imagedata(min(75, int(height))) except (ValueError, AttributeError): raise ValueError("Cannot convert into barcode.")
def test_against_dmtx(self): """Compare the output of this library with that of dmtxwrite""" for string in MatrixTest.test_strings: encoder = DataMatrixEncoder(string) mine = encoder.get_ascii() if not os.path.exists(dmtxwrite_path): print("%r does not exist, skipping encoding tests" % dmtxwrite_path) else: fin = os.popen("%s '%s'" % (dmtxwrite_path, string)) output = "" while True: line = fin.readline() if not line: break if line[0] == 'X': output += line self.assertEqual(output, mine)
def generateDatamatrix(batch_id): """ Générer la datamatrix d'un lot à l'aide de l'ID de lot """ batch = Batch.query.filter_by(batch_id=batch_id).first_or_404() medicine = Medicine.query.filter_by(medicine_id=batch.medicine_id).first() balise01 = "ASCII232" balise02 = "ASCII29" gtin = medicine.GTIN exp_date = batch.exp_date lot = batch.batch_id free_data = "" data = str(balise01) + "01" + str(gtin) + "17" + str( exp_date) + "10" + str(lot) + str(balise02) + "91" + str(free_data) datamatrix_data = DataMatrixEncoder(data) return data
from pystrich.datamatrix import DataMatrixEncoder a = '[)>\u001E06\u001DL5c70984512875079b91f8949\u001DT5c70984512875079b91f8949\u001D1P5c70984512875079b91f8949\u001D5D201229\u001E\u0004' encoder = DataMatrixEncoder(a) encoder.save("datamatrix.packet.png")
def datamatrix(signature): m = DataMatrixEncoder(signature) r = DataMatrixRenderer(m.matrix, m.regions) return r.get_pilimage(2)
from pystrich.datamatrix import DataMatrixEncoder encoder = DataMatrixEncoder('Hello') print(encoder.get_ascii())
from pystrich.datamatrix import DataMatrixEncoder encoder = DataMatrixEncoder('data matrix') encoder.save("/.datamatrix_test.png") print(encoder.get_ascii())
# IDV ---------------------------------- 2 # Código de Rastreamento --------------- 13 # Serviços Adicionais (AR, MP, DD, VD) - 8 # Cartão de Postagem ------------------- 10 # Código do Serviço -------------------- 5 # Informação de Agrupamento ------------ 2 # Número do Logradouro ----------------- 5 # Complemento do Logradouro ------------ 20 # Valor Declarado ---------------------- 5 # DDD + Telefone Destinatário ---------- 12 # Latitude ----------------------------- 10 # Longitude ---------------------------- 10 # Pipe "|" ----------------------------- 1 # Reserva para cliente ----------------- 30 encoder_dm = DataMatrixEncoder( '12221150000001620312500000651OO382192458BR0000000000000075022907041621I0000000000000000000000000000000000000|' ) encoder_dm.save('matrix.png') # codigo de rastreio cod_rastreio = Code128Encoder('OO382192458BR') cod_rastreio.save('cod_rastreio.png') # cep de destino cep_destino = Code128Encoder('12221150') cep_destino.save('cep_destino.png') # converte html em pdf pdfkit.from_file('etiqueta.html', 'etiqueta.pdf') # imprime etiqueta
# Sample taken from pyStrich GitHub repository # https://github.com/mmulqueen/pyStrich from pystrich.datamatrix import DataMatrixEncoder x = input(" Please enter your name: ") print("Welcome", x) encoder = DataMatrixEncoder(x) encoder.save('./datamatrix_test.png') print("This is your name as a DataMatrix: ", encoder.get_ascii())
# Sample taken from pyStrich GitHub repository # https://github.com/mmulqueen/pyStrich from pystrich.datamatrix import DataMatrixEncoder encoder = DataMatrixEncoder('This is a DataMatrix.') encoder.save('./datamatrix_test.png') print(encoder.get_ascii())
def hello(): encoder = DataMatrixEncoder('This is a DataMatrix.') encoder.save('./datamatrix_test.png') print(encoder.get_ascii()) return "Hello World!"
"""Example code for datamatrix library""" __revision__ = "$Revision$" from pystrich.datamatrix import DataMatrixEncoder import sys import logging import os.path sys.path.append( os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir)) logging.getLogger("datamatrix").setLevel(logging.DEBUG) logging.getLogger("datamatrix").addHandler(logging.StreamHandler(sys.stdout)) if __name__ == "__main__": encoder = DataMatrixEncoder(sys.argv[1]) encoder.save("test.png") print(encoder.get_ascii()) with open("test.dxf", "w") as text_file: text_file.write(encoder.get_dxf(inverse=True, cellsize=0.1))
#sample taken from pyStrich GitHub repository # https://github.com/mmulqueen/pyStrich from pystrich.datamatrix import DataMatrixEncoder encoder = DataMatrixEncoder('This is a DataMatrix.') encoder.save('./datamatrix_test.png') print(encoder.get_ascii())
# Sample taken from pyStrich GitHub repository # https://github.com/mmulqueen/pyStrich from pystrich.datamatrix import DataMatrixEncoder encoder = DataMatrixEncoder('This is a DataMatrix.') encoder.save('./datamatrix_Street View Motion-from-Structure-from-Motiontest.png') print(encoder.get_ascii()) print("This is a Docerk test for IS601001, Windows 10, by Huan")
def get(self): task = self.get_argument('task', None) skip = int(self.get_argument('skip', 0)) if task: print(task) task_data = self.mdb.label_generation.find_one( {'_id': ObjectId(task)}) print(task_data) group = task_data['type'] items = task_data['items'] else: data = self.get_argument('data', None) group = self.get_argument('group', None) if group == 'labels': length = len(items) items = list(self.mdb.store_labels.find({"_id": {"$in": items}})) pdf = FPDF('P', 'mm', format='A4') pdf.set_auto_page_break(False) pdf.add_font('pt_sans', '', 'static/pt_sans/PT_Sans-Web-Regular.ttf', uni=True) pdf.add_font('pt_sans-bold', '', 'static/pt_sans/PT_Sans-Web-Bold.ttf', uni=True) pdf.set_font('pt_sans', '', 12) pdf.add_page() page = 0 warehouse_name = self.get_warehouse().get('name', "Neni nastaven") for i, label in enumerate(items): pdf.set_text_color(0) ir = i + skip ip = ir % (3 * 7) row = ip // 3 cell = ip % 3 print(i, ir, ip, row, cell) if page != (ir // (3 * 7)): print("NOVA STRANKA", ir // (3 * 7)) pdf.add_page() page = ir // (3 * 7) x0 = 70 * cell y0 = (297 / 7) * row #pdf.set_draw_color(231, 221, 25) pdf.set_fill_color(231, 121, 25) pdf.set_xy(x0, y0 + 4) pdf.rect(x0, y0 + 12.5, w=70, h=8.4, style='F') pdf.set_font('pt_sans-bold', '', 14) pdf.set_xy(x0, y0 + 8.5) pdf.cell(70, 0, label['name'][:25], align='C') pdf.set_font('pt_sans', '', 11) pdf.set_xy(x0 + 3.5, y0 + 13.5) pdf.multi_cell(70 - 4, 3.4, label['text'], align='L') pdf.set_text_color(100) # pdf.set_font('pt_sans', '', 8) # pdf.set_xy(x0+2, y0+2.5) # pdf.cell(70, 0, "Pozice: {}".format(warehouse_name)) id = str(position['_id']) barcode_content = "[)>\u001E06\u001DL{posID}\u001DT{packetId}\u001D1P{componentId}\u001D5D{Date}\u001E\u0004".format( posID="", packetId=id, componentId="", Date="20200101") encoder = DataMatrixEncoder(a) encoder.save("static/tmp/barcode/%s.png" % (id)) pdf.set_font('pt_sans', '', 7) pdf.set_xy(x0, y0 + 30) pdf.cell(70, 0, barcode, align='C') pdf.set_font('pt_sans', '', 7) pdf.set_xy(x0 + 3.5, y0 + 33) pdf.cell( 70, 0, "{} | {}".format( warehouse_name, datetime.datetime.now().strftime("%d. %m. %Y, %H:%M"))) print(label['category']) pdf.output('static/tmp/{}.pdf'.format(task), 'F') gen_time = datetime.datetime(2018, 10, 1) lastOid = ObjectId.from_datetime(gen_time) print(self.get_warehouse()) self.write('/static/tmp/{}.pdf'.format(task)) else: self.write("OK")
"hook", "layer", "lie", "manner", "nose", "rice", "tip", "winter", "bag", "battle", "bed", "bill", "bother", "cake", "code", "curve", "dress", "ease", "farm", "fight", "gap", "grade", "horror", "horse", "host", "loan", "nail", "noise", "pause", "phrase", "proof", "race", "relief", "sand", "smoke", "string", "towel", "west", "wheel", "wine", "arm", "aside", "bet", "blow", "border", "branch", "breast", "buddy", "bunch", "chip", "coach", "cross", "draft", "dust", "expert", "floor", "golf", "habit", "iron", "judge", "knife", "league", "mail", "mess", "native", "parent", "pin", "pool", "pound", "salary", "shame", "shoe", "silver", "tackle", "tank", "trust", "assist", "bake", "bar", "bell", "bike", "blame", "boy", "brick", "chair", "closet", "clue", "collar", "devil", "diet", "fear", "fuel", "glove", "jacket", "lunch", "nurse", "pace", "panic", "peak", "plane", "reward", "row", "shock", "spite", "spray", "till", "yard", "alarm", "bend", "bite", "blind", "bottle", "cable", "candle", "clerk", "cloud", "flower", "harm", "knee", "lawyer", "load", "mirror", "neck", "plate", "purple", "ruin", "ship", "skirt", "slice", "snow", "stroke", "switch", "trash", "tune", "zone", "anger", "award", "bid", "bitter", "boot", "bug", "camp", "candy", "carpet", "cat", "clock", "cow", "crack", "fault", "grass", "guy", "hell", "island", "joke", "jury", "leg", "lip", "mate", "motor", "nerve", "pen", "pride", "priest", "prize", "resort", "ring", "roof", "rope", "sail", "scheme", "script", "sock", "toe", "tower", "truck", ] if __name__ == '__main__': print(len(ADJECTIVES) * len(NOUNS)) for i in range(0, 500): code = random.choice(ADJECTIVES) + "-" + random.choice(NOUNS) print(code) DataMatrixEncoder(code).save(code + '.png')
def gen_pdf(self, data): a4_w = 210 a4_h = 297 pdf = FPDF('P', 'mm', (a4_w, a4_h)) pdf.set_auto_page_break(False) pdf.add_font('pt_sans', '', 'static/pt_sans/PT_Sans-Web-Regular.ttf', uni=True) pdf.add_font('pt_sans-bold', '', 'static/pt_sans/PT_Sans-Web-Bold.ttf', uni=True) pdf.set_font('pt_sans', '', 11) pdf.add_page() page = 0 skip = 0 warehouse_name = self.get_warehouse().get('name', "Neni nastaven") for i, label in enumerate(data): #print(".....") #print(label) pdf.set_text_color(0) ir = i + skip # cislo bunky ip = ir % (3 * 7) # cislo bunky na strance row = ip // 3 # cislo radku cell = ip % 3 # cislo sloupce actual_page = ir // (3 * 7) # cislo stranky #print(i, ir, ip, row, cell) if page != actual_page: print("NOVA STRANKA", actual_page) pdf.add_page() page = actual_page #x0 = 70*cell #y0 = (297/7)*row label_width = 69.7 label_height = 42 x0 = a4_w / 2 + (-1.5 + cell) * label_width y0 = a4_h / 2 + (-3.5 + row) * label_height + 2 id = str(label['id']) printed_id = id if label['type'] == 'packet': packet = label['packet'] pdf.set_text_color(150) pdf.set_font('pt_sans', '', 6) pdf.set_xy(x0 + 4, y0 + 1) pdf.cell(label_width - 8, 4.5, "Packet", align='L') # nazev soucastky pdf.set_draw_color(10) pdf.set_fill_color(245) pdf.set_text_color(0) pdf.set_font('pt_sans-bold', '', 12) pdf.set_xy(x0 + 5, y0 + 4.5) label_name = label['component']['name'] if len(label_name) > 40: label_name = label_name[40:] + ".." name_length = pdf.get_string_width(label_name) if name_length > 58: for size in range(0, 70): pdf.set_font('pt_sans-bold', '', 12 - size / 10) name_length = pdf.get_string_width(label_name) if name_length < 58: print("Zmenseny nazev, velikost", 12 - size / 10) break print("DELKA:", pdf.get_string_width(label_name), label_name) pdf.cell(label_width - 10, 4.5, label_name, align='L', border=1) pdf.set_font('pt_sans', '', 8) ## print(label.keys()) id = str(label['_id']) barcode = "[)>\u001E06" # format 06 header barcode += "\u001DS{}".format(label['id']) ## Sacek #barcode += "\u001D1P{}".format(label['component']['_id']) # component identificator by supplier # barcode += "\u001D30P{}".format(label['component']['name']) # Component identificator by supplier - 1st level barcode += "\u001D5D{}".format( datetime.datetime.now().strftime("%y%m%d")) barcode += "\u001E\u0004" # end of barcode encoder = DataMatrixEncoder(barcode) encoder.save("static/tmp/barcode/%s.png" % (id)) pdf.set_xy(x0 + label_width - 20 - 4, y0 + 8 + 7) pdf.image('static/tmp/barcode/%s.png' % (id), w=20, h=20) # Popis stitku pdf.set_text_color(20) pdf.set_font('pt_sans', '', 8) description = label['component'].get('description', '')[:110].strip() pdf.set_xy(x0 + 4, y0 + 15) pdf.multi_cell(label_width - 28, 2.8, description, align='L', border=0) # pozice ve skaldu, oznaceni stitku uzivatelskym kodem pdf.set_text_color(0) pdf.set_xy(x0 + label_width - 19, y0 + 10) pdf.set_font('pt_sans-bold', '', 9) pdf.cell(14, 5, label['packet']['name'], align="R", fill=True) pdf.set_text_color(80) pdf.set_xy(x0 + 5, y0 + 10) if "warehouse" in label: pos = "/" for p in reversed(label['path']): pos += p['name'] + "/" pos += label['position']['name'] pdf.set_font('pt_sans-bold', '', 9) pdf.multi_cell(label_width - 29, 3, pos, align='L') pdf.set_font('pt_sans', '', 8) pdf.set_text_color(80) pdf.set_xy(x0 + 32, y0 + 32) pdf.cell(14, 3.5, label['warehouse']['code'].upper(), align="R") else: pdf.set_text_color(120) pdf.set_font('pt_sans', '', 10) pdf.write(5, "Mimo skladu") cat_text = "" if "category" in label: pos = [] cat_text = " | cat: " for c in label['category']: pos += [c['name']] cat_text += ','.join(pos) pdf.set_font('pt_sans', '', 9) pdf.set_text_color(60) pdf.set_xy(x0 + 4, y0 + 34.5) pdf.cell(0, 0, "{} ks".format(packet['packet_count']), align="L") printed_id = packet['_id'] # Zkus najit dodavatele sacku. Pokud to nejde, nevadi.. proste tam nic nebude try: supplier_order = int(packet['supplier']) supplier_info = packet['component'][0]['supplier'][ supplier_order] supplier_text = supplier_info.get( 'supplier', "NA") + " | " + supplier_info.get( 'symbol', "NA") pdf.set_font('pt_sans', '', 8) pdf.set_text_color(100) pdf.set_xy(x0 + 4, y0 + 29) pdf.cell(label_width - 28, 4.5, supplier_text, align='L', border=0) except: pass if label['type'] == 'position': #packet = label['packet'] position = label['position_label'] ## Vzhled pozic pdf.set_fill_color(220, 255, 220) pdf.rect(x0 + 1, y0 + 1, w=label_width - 2, h=label_height - 2, style='F') pdf.set_fill_color(100, 220, 100) pdf.rect(x0 + 5, y0 + 4.5, w=label_width - 10, h=4.5, style='F') pdf.set_text_color(100) pdf.set_font('pt_sans', '', 6) pdf.set_xy(x0 + 4, y0 + 1) pdf.cell(label_width - 8, 4.5, "Pozice", align='L') pdf.set_text_color(0) pdf.set_font('pt_sans-bold', '', 12) pdf.set_xy(x0 + 5, y0 + 4.5) pdf.cell(label_width - 10, 4.5, position['position']['name'][:25], align='L', border=1) pdf.set_xy(x0 + 4, y0 + 16) pdf.set_font('pt_sans', '', 12) #pdf.write(5, position['position']['text']) pdf.multi_cell(label_width - 28, 5, position['position']['text'][:80], align='L') barcode = "[)>\u001E06" # format 06 header barcode += "\u001D1L{}".format(id) ## Pozice #barcode += "\u001D1P{}".format(label['component']['_id']) # component identificator by supplier #barcode += "\u001D5D{}".format(datetime.datetime.now().strftime("%y%m%d")) barcode += "\u001E\u0004" # end of barcode encoder = DataMatrixEncoder(barcode) encoder.save("static/tmp/barcode/%s.png" % (id)) pdf.set_xy(x0 + label_width - 20 - 4, y0 + 8 + 7) pdf.image('static/tmp/barcode/%s.png' % (id), w=20, h=20) pdf.set_font('pt_sans', '', 6) pdf.set_text_color(100) pdf.set_xy(x0 + 0, y0 + 7) # pdf.cell(65, 0, , align = 'R') # Cesta pdf.set_xy(x0 + 4, y0 + 10) pdf.set_font('pt_sans', '', 10) pdf.write(5, position['position']['warehouse']['code'].upper()) pdf.set_font('pt_sans', '', 12) path = '/'.join((position['position']['path_string'])) if len(path) > 0: path = "/" + path pdf.write(5, path) # pdf.set_font('pt_sans-bold', '', 12) # pdf.write(5, position['position']['name']) # pdf.set_xy(x0+4, y0+10) # pdf.set_font('pt_sans-bold', '', 10) # path = position['position']['warehouse']['code'].upper() + "/" + path # pdf.multi_cell(70-28, 2.8, path, align='L') # pozice ve skaldu pdf.set_text_color(100) pdf.set_xy(x0 + 4, y0 + 8.8) print(">>>") print(label) else: pass pdf.set_text_color(100) pdf.set_font('pt_sans', '', 7) pdf.set_xy(x0, y0 + 37) pdf.cell(label_width, 0, "UST.cz|{}|{}".format( datetime.datetime.now().strftime("%d.%m. %Y,%H:%M"), printed_id), align="C") task = "tisk" pdf.output('static/tmp/{}.pdf'.format(task), 'F') gen_time = datetime.datetime(2018, 10, 1) lastOid = ObjectId.from_datetime(gen_time) self.redirect('/static/tmp/{}.pdf'.format(task))
from pystrich.datamatrix import DataMatrixEncoder encoder = DataMatrixEncoder('This is my message') encoder.save('./datamatrix.png') print(encoder.get_ascii())
"""Example code for datamatrix library""" __revision__ = "$Revision$" import pystrich from pystrich.datamatrix import DataMatrixEncoder import sys import logging import os.path sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir)) logging.getLogger("datamatrix").setLevel(logging.DEBUG) logging.getLogger("datamatrix").addHandler(logging.StreamHandler(sys.stdout)) if __name__ == "__main__": encoder = DataMatrixEncoder(sys.argv[1]) encoder.save("test.png") print(encoder.get_ascii())
#/usr/bin/python3 # Copied from video from pystrich.datamatrix import DataMatrixEncoder encoder = DataMatrixEncoder("This is a DataMatrix.") encoder.save("/datamatrix_test.png") print(encoder.get_ascii())
"""Example code for datamatrix library""" __revision__ = "$Revision$" from pystrich.datamatrix import DataMatrixEncoder import sys import logging import os.path sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir)) logging.getLogger("datamatrix").setLevel(logging.DEBUG) logging.getLogger("datamatrix").addHandler(logging.StreamHandler(sys.stdout)) if __name__ == "__main__": encoder = DataMatrixEncoder(sys.argv[1]) encoder.save("test.png") print(encoder.get_ascii())
for x in range(1, 3): # hex_string = str(binascii.b2a_hex(os.urandom(15))) # hex_string = str(secrets.token_hex(84).upper()) hex_sinput = str(random.randint(10, 33)) + str( random.randint(10, 33)) + str(random.randint(10, 33)) + str( random.randint(10, 33)) + str(random.randint(10, 33)) hex_sinput = hex_sinput.strip().replace(' ', '') hex_sinput = hex_sinput + hex_sinput + "00000000000000000000000000000000000000000000000000000000" # sys.exit() # for x in arrayHex: # print(x) # sys.exit() encoder = DataMatrixEncoder( bytes.fromhex(hex_sinput).decode('iso-8859-1')) # iso-8859-15 # encoder = DataMatrixEncoder(hex_string) # iso-8859-15 encoder.save("sample_barcodes/datamatrix_test_" + str(x) + ".png") # print(encoder.get_ascii()) bashCommand = "dmtxread -v -N 1 sample_barcodes/datamatrix_test_" + str( x) + ".png | tail -n 1 | od -An -vtx1" # os.system(bashCommand) hex_string = os.popen(bashCommand).read() hex_output = hex_string.strip().replace(' ', '') hex_output = hex_output.replace("\n", '') if hex_sinput == hex_output: print("[ PYTHON DMTXREAD DECODED BIN2HEX REVERS OK] ") print("[ SINPUT HEX: " + hex_sinput + " ]") print("[ OUTPUT HEX: " + hex_output + " ]")