def test_saving_rgba_image():
        rv = BytesIO()
        EAN13(str(100000902922), writer=ImageWriter()).write(rv)

        with open(f"{TESTPATH}/ean13-with-transparent-bg.png", "wb") as f:
            writer = ImageWriter(mode="RGBA")

            EAN13("100000011111", writer=writer).write(
                f, options={"background": "rgba(255,0,0,0)"})
Exemple #2
0
def qr_generator():

    #option 1 print to a file-like object:
    rv = io.BytesIO()
    EAN13('123581321340', writer=ImageWriter()).write(rv)
    image = Image.open(rv)
    image = image.resize((400, 400), Image.ANTIALIAS)
    image.show()

    # option 2, to an actual file:
    with open('QR-generator.jpeg', 'wb') as f:
        EAN13('123581321340', writer=ImageWriter()).write(f)
def randomEAN13() -> np.ndarray:
    number = ''.join(random.choice(string.digits) for i in range(12))
    my_code = EAN13(number, writer=ImageWriter())
    my_code.save("new_code", None, None)
    temp = cv2.imread("new_code.png")
    temp = temp[0:220, 40:480]
    return temp
Exemple #4
0
def generate_barcode(num):
    # Now, let's create an object of EAN13 class and
    # pass the number with the ImageWriter() as the writer
    my_code = EAN13(num, writer=ImageWriter())

    # Our barcode is ready. Let's save it.
    my_code.save("bar_code1")
Exemple #5
0
    def readImageNs(self, name, i, filename, gtin):
        koord = [[0, 415],
                 [420, 835],
                 [840, 1255],
                 [1260, 1675],
                 [1680, 2095],
                 [2105, 2520],
                 [2525, 2940],
                 [2945, 3360]]
        page = int(i / 8)
        n = i % 8
        print("Page %s" % (page))
        print("Image %s" % (n))

        print(gtin[1:14])
        with open('ean.png', 'wb') as f:
            EAN13('%s' % (gtin[1:13]), writer=ImageWriter()).write(f)

#        with  Image(filename='%s[%s]' % (name, page), resolution=300) as img:
        if page != self.page:
            self.image = Image(filename='%s[%s]' % (self.pdf, page), resolution=300)
            self.page = page

        with self.image.clone() as img:
            img.convert('png')
            img.crop(0, koord[n][0], 709, koord[n][1])
            draw = Drawing()
            ean = Image(filename="./ean.png", resolution=300).clone()
            draw.composite(operator="over", left=5, top=235, width=round(ean.width * 0.65),
                           height=round(ean.height * 0.65), image=ean)
            draw(img)
            img.save(filename='%s.png' % (filename))
 def codebarImg(self, codebar):
     if (len(codebar) == 13):
         print("Predicted to have a EAN13 barcode")
         try:
             codebarImg = EAN13(codebar, writer=ImageWriter())
         except:
             ""
     elif (len(codebar) == 8):
         print("Predicted to have a EAN8 barcode")
         try:
             codebarImg = EAN8(codebar, writer=ImageWriter())
         except:
             ""
     elif (len(codebar) == 14):
         print("Predicted to have a EAN14 barcode")
         try:
             codebarImg = EAN14(codebar, writer=ImageWriter())
         except:
             ""
     else:
         print("Predicted to have a Code128 barcode")
         try:
             codebarImg = Code128(codebar, writer=ImageWriter())
         except:
             ""
     return codebarImg
Exemple #7
0
    def export(self):
        os.system("mkdir barcodes")
        x_images = 0
        y_images = 0
        pages = 0
        stiched = None
        stiched_row = None

        fnt = ImageFont.truetype("Pillow/Tests/fonts/FreeMono.ttf", 20)
        spacer_vert_width = 80
        spacer_vert = Image.new('RGB', (spacer_vert_width, 250),
                                (255, 255, 255))
        top_spacer = Image.new('RGB', (4 * 523 + 4 * spacer_vert_width, 25),
                               (255, 255, 255))
        print("Number: ", len(self.barcodes))
        for tool in self.barcodes:

            with open("barcodes/" + str(tool[0]) + ".png", 'wb') as f:
                EAN13(str(tool[0]), writer=ImageWriter()).write(f)

            image = Image.open("barcodes/" + str(tool[0]) + ".png")
            image = image.crop((0, 30, 523, 280))

            d_con = ImageDraw.Draw(image)
            d_con.multiline_text((80, 165),
                                 tool[1] + " " + tool[2],
                                 font=fnt,
                                 fill=(0, 0, 0))
            d_con.multiline_text((80, 190),
                                 tool[3] + " / " + tool[4] + " GV",
                                 font=fnt,
                                 fill=(0, 0, 0))

            if x_images == 0:
                stiched_row = np.concatenate((spacer_vert, image), axis=1)

                x_images += 1
            elif x_images % 4 != 0:
                stiched_row = np.concatenate((stiched_row, spacer_vert, image),
                                             axis=1)
                x_images += 1
            elif x_images % 4 == 0 and x_images != 0:
                if y_images == 0:
                    stiched = stiched_row
                    y_images += 1

                elif y_images == 12:

                    final = np.concatenate((top_spacer, stiched), axis=0)
                    im = Image.fromarray(final)
                    im.save("page" + str(pages) + ".pdf", "PDF")
                    y_images = 0
                else:
                    stiched = np.concatenate((stiched, stiched_row), axis=0)
                    y_images += 1
                stiched_row = None
                x_images = 0

        os.system("rm -r barcodes")
def generateSticker(model, size, gtin, serial, dmC):
    lim = 1.2
    w = round( dmC.width * lim )
    h = round( dmC.height * lim )
    print( "%s %s %s %s" % ( model, size, gtin, serial ) )
#    os.system( 'zint --height 20 -o ean.png -b 13 -d "%s"'%( gtin[5:17] ) )
    print(gtin)
    print( gtin[5:18] )
    with open( 'ean.png', 'wb' ) as f:
        EAN13( '%s' % (gtin[5:18]), writer = ImageWriter() ).write( f )
    dmCode = dmC
    dmCode = dmCode.resize( (w, h) )
    img = Image.open("./maket.png")
    img.paste( dmCode, box = (600, 70))

    ean = Image.open("./ean.png")
    ean = ean.crop( (60, 1, 500, 150) )
    img.paste( ean, box = (95, 645))

    w = round( len( model ) * 30 / 2 )
    print( w )

    txt = Image.new( "RGBA", img.size, (255, 255, 255, 0) )
    fnt = ImageFont.truetype( "Pillow/Tests/fonts/FreeMonoBold.ttf", 90 )
    fnt1 = ImageFont.truetype( "Pillow/Tests/fonts/FreeMonoBold.ttf", 45 )

    # get a drawing context
    d = ImageDraw.Draw( txt )

    # draw text, half opacity
    d.text( (100, 130), model, font = fnt, fill = (0, 0, 0, 255) )
    # draw text, full opacity
    d.text( (230, 330), size, font = fnt, fill = (0, 0, 0, 255) )

    d.text( (550, 570), gtin, font = fnt1, fill = (0, 0, 0, 255) )
    d.text( (650, 670), serial, font = fnt1, fill = (0, 0, 0, 255) )

    img = Image.alpha_composite( img, txt )

#    draw.font_size = 110
#    draw.text( 320 - w, 240, model )
#    draw.text( 250, 420, size )
#    draw.font_size = 70



#     draw.font_size = 50
#     draw.text( 580, 630, gtin )
#     draw.text( 680, 720, serial )
#
#     draw( img )
    now = datetime.datetime.now()
    name = "./images/m%s_s%s_%s_%s_%s_%s_%s_%s_%s.png" % ( model, size, now.year,
                                                           now.month, now.day, now.hour,
                                                           now.minute, now.second,
                                                           now.microsecond )
    print(name)
    img.save(name)
    dmCode.save("dout.png")
Exemple #9
0
def gcb():
    cod = randint(100000000000, 9999999999999)
    valor = validarcodigo(str(cod))
    while valor == True:
        valor = validarcodigo(cod)
    rv = BytesIO()
    EAN13(str(cod), writer=ImageWriter()).write(rv)
    return cod, rv
def bar_generator(digits=123456789123):
    # digits=123456789123 is a default value, if no other values is passed.
    # io.BytesIO makes sure you only save to memory instead of disk.
    rv = io.BytesIO()
    EAN13(str(digits), writer=ImageWriter()).write(rv)
    image = Image.open(rv)
    # Resize and display the BAR code
    image = image.resize((400, 400), Image.ANTIALIAS)
    image.show()
    def generate_barcode_image(self):

        image = ImageFile(f'/tmp/{self.local_barcode}.jpeg')

        with open(image.file, 'wb') as f:
            EAN13(self.local_barcode, writer=ImageWriter()).write(f)

        with open(image.file, 'rb') as f:
            self.local_barcode_image.save(f'{self.local_barcode}.jpeg', ImageFile(f), save=False)

        os.unlink(image.file)
Exemple #12
0
def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    code = req.params.get('code',"").strip()
    if len(code)!=12 or not code.isdigit():
        return func.HttpResponse("Za mało cyfr lub niepoprawne dane", status_code=500)
    
    fd = BytesIO()
    EAN13( code, writer=ImageWriter()).write(fd)
    fd.seek(0)
    return func.HttpResponse(fd.read(-1) , status_code=200, mimetype="image/jpg" )
Exemple #13
0
def main():
    print("Hello, Dr. Han!!!!!!!")
    img = Image.open('Images/ocrtest.jpg').convert('L')
    ret, img = cv.threshold(np.array(img), 125, 255, cv.THRESH_BINARY)
    img = Image.fromarray(img.astype(np.uint8))
    """here we are extracting 13 digit numbers that begin with 0108.
    We'll need an option to enter store number for beginning of string."""
    containerIDs = re.findall('0108[0-9]{9}', image_to_string(img))
    for id in containerIDs:
        print(id)
    for count, container in enumerate(containerIDs):
        ean = EAN13(container, writer=ImageWriter())
        ean.save('Images/Barcodes/{}'.format(count))
def generateBarcode():
    param_msg = str(request.form['message'])
    print(param_msg)
    barCode = EAN13(param_msg, writer=ImageWriter())
    barCode.save("static/Images/BarCode")
    res = []
    # with open("./BarCode.png", "rb") as image:
    #     encoded_string = base64.b64encode(image.read())
    #     res.append(encoded_string.decode("utf-8"))
    # full_filename = os.path.join('BarCode.png')
    # print(full_filename)
    full_filename = os.path.join(app.config['UPLOAD_FOLDER'], 'BarCode.png')
    # return render_template("index.html", user_image=full_filename)
    print(full_filename)

    return render_template("barcode.html",
                           sentence=param_msg,
                           output="Barcode has been generated successfully",
                           user_image=full_filename)
Exemple #15
0
from barcode import EAN13
from barcode.writer import ImageWriter

# EAN13의 객체를 생성
my_code = EAN13('9002236311037', writer=ImageWriter())

# 바코드를 저장
my_code.save("./example/barcode/barcode_2")
def test_saving_svg_to_byteio_with_guardbar():
    rv = BytesIO()
    EAN13(str(100000902922), writer=SVGWriter(), guardbar=True).write(rv)

    with open(f"{TESTPATH}/somefile_guardbar.svg", "wb") as f:
        EAN13("100000011111", writer=SVGWriter(), guardbar=True).write(f)
Exemple #17
0
from barcode import EAN13
from barcode.writer import ImageWriter
from PIL import Image

with open(r'barcode.png', 'wb') as f:
    EAN13('012345678913', writer=ImageWriter()).write(f)

    img = Image.open('barcode.png')
    img.show()
    def test_saving_image_to_byteio():
        rv = BytesIO()
        EAN13(str(100000902922), writer=ImageWriter()).write(rv)

        with open(f"{TESTPATH}/somefile.jpeg", "wb") as f:
            EAN13("100000011111", writer=ImageWriter()).write(f)
Exemple #19
0
	def generate_kit_code_img(self):
		with open(self.img_name, "wb") as f:
			EAN13(str(self.kit_code), writer=ImageWriter()).write(f)
Exemple #20
0
 def bar_generator(digits):
     rv = io.BytesIO()
     EAN13(str(digits), writer = ImageWriter()).write(rv)
     image = Image.open(rv)
     image = image.resize((400, 400), Image.ANTIALIAS)
     image.show()
Exemple #21
0
    Require Pillow to export to jpg

example of bar code generator

@author: Mariusz
"""

from barcode import EAN13, PZN
from barcode.writer import ImageWriter
from io import BytesIO
from wand.image import Image

# print to a file-like object:
rv = BytesIO()
PZN(str(100000902922), writer=ImageWriter()).write(rv)
EAN13(str(100000902922), writer=ImageWriter()).write(rv)

# or sure, to an actual file:
with open('barcodePZN.jpeg', 'wb') as f:
    PZN('100000011111', writer=ImageWriter()).write(f)

with open('barcodeEAN13.jpeg', 'wb') as f:
    EAN13('100000011111', writer=ImageWriter()).write(f)

# Save as SVG using wand (image Magick)
import barcode
#from wand.image import Image

EAN = barcode.get_barcode_class('ean13')
#ean = EAN(u'123456789011', writer=ImageWriter())
ean = EAN(u'123456789011', writer=Image())
from barcode import EAN13
from barcode.writer import ImageWriter

# Gera o código de barras e salva no caminho desejado #
with open(r'D:\pycode\bar-code-generator\barcode.png', 'wb') as f:
    EAN13('123456789102', writer=ImageWriter()).write(f)
Exemple #23
0
from barcode import EAN13
from barcode.writer import ImageWriter

# Write to an image
with open('barcode.jpeg', 'wb') as f:
    EAN13('100000011111', writer=ImageWriter()).write(f)
Exemple #24
0
    # Цвет металла
    cvet_format = doc.add_format({
        'font_name': 'Times New Roman',
        'font_size': 5,
        'text_h_align': 3,  # right
        'text_v_align': 2,
    })
    doc_ws.merge_range(start_row + 5, start_col, start_row + 5, start_col + 17,
                       f'Цв. {elem[10]}', cvet_format)

    # Покрытие

    # Штрихкод
    image_data = BytesIO()
    ean = EAN13(str(elem[12]), writer=ImageWriter())
    ean.write(image_data, options={"write_text": False})

    x_scale = 0.21  # *13.89
    y_scale = 0.115  # *5.39

    doc_ws.insert_image(
        f'A{start_row+7}', str(elem[12]), {
            'image_data': image_data,
            'x_offset': 0,
            'y_offset': 0,
            'x_scale': x_scale,
            'y_scale': y_scale,
            'object_position': 0,
        })
Exemple #25
0
def generacodigo(cod):
    rv = BytesIO()
    EAN13(str(cod), writer=ImageWriter()).write(rv)
    return rv
def generator(number):
    my_code = EAN13(number, writer=ImageWriter())
    my_code.save("bar_code")
Exemple #27
0
from barcode import EAN13
from barcode.writer import ImageWriter

#input your number here as a string
#tam 12
number = '123456789012'

my_code = EAN13(number, writer=ImageWriter())
my_code.save('new_code1')
Exemple #28
0
#pip install python-barcode
#pip install pillow
from barcode import EAN13
from barcode.writer import ImageWriter

codigos_produtos = {
    "Feijão": "553214569874",
    "Arroz": "123456789101",
    "Macarrao": "564895521455",
    "Azeite": "444523669874"
}

for produto in codigos_produtos:
    codigo = codigos_produtos[produto]
    #Precisa de doze digitos
    codigo_barra = EAN13(codigo, writer=ImageWriter())
    codigo_barra.save(f"codigo_barra_{produto}")
from barcode import EAN13

# Make sure to pass the number as string
number = '5901234123457'

# Now, let's create an object of EAN13
# class and pass the number
my_code = EAN13(number)
my_code.default_writer
# Our barcode is ready. Let's save it.
my_code.save("new_code.svg", options={"module_width": 0.2, "module_height": 7})
Exemple #30
0
 def Generate_bar(self):
     # creemos un objeto de clase EAN13 y pasar el número
     # con ImageWriter() para escribir en la imagen
     self.code_bar = EAN13(self.number, writer=ImageWriter())
     # Guardamos nuesto archivo imagen.
     self.code_bar.save(self.filename)