def print_task(printer, label):
    selected_backend = guess_backend(printer.connection)
    BACKEND_CLASS = backend_factory(selected_backend)['backend_class']

    image = img_label(label)

    # from brother_ql
    qlr = BrotherQLRaster(printer.model)

    create_label(qlr,
                 image,
                 printer.width,
                 threshold=70,
                 cut=True,
                 dither=False,
                 compress=False,
                 red=False)

    try:
        be = BACKEND_CLASS(printer.connection)
        be.write(qlr.data)
        be.dispose()
        del be
    except Exception as e:
        raise NameError(str(e))

    return True
Beispiel #2
0
    def print_image(self, image: Image, red=False):
        raster = BrotherQLRaster(self.model)
        print_data = brother_ql.brother_ql_create.convert(raster, [image], str(self.label_width), dither=True)
        self.backend.write(print_data)
        start = time.time()
        while True:
            data = attempt_read(self.backend)
            if data:
                self.status = parse(data)
                print(self.status)

                if self.status.status_type == StatusType.ErrorOccurred:
                    logger.info(f"Error occurred while printing {self.serial}")
                    break

                if self.status.status_type == StatusType.PrintingComplete:
                    break

            time.sleep(0.2)

            if time.time() - start > 3:
                logger.info(f"Status timeout while printing on {self.serial}")
                break

        # send initialize
        self.backend.write(b'\x1b\x40')

        del raster
Beispiel #3
0
    def __init__(self, picname: str,
                 config: tp.Dict[str, tp.Dict[str, tp.Any]]) -> None:
        """
        :param picname: path to a picture to be printed
        :type picname: str

        When creating an instance of the class, it creates a task for a brother QL-800 printer to print a label with a
        qr-code passed as an argument. picname != qrpic, it contains side fields and logos (optionally)
        """

        logging.info("Initializing printer")

        qr = Image.open(picname)
        printer_config: tp.Dict[str, tp.Any] = config["printer"]
        printer: str = printer_config["address"]  # link to device
        label_name = str(printer_config["paper_width"]
                         )  # that depends on paper used for printing

        logging.info("Printing...")
        qlr = BrotherQLRaster(printer_config["printer_model"])
        red: bool = (label_name == "62")
        conversion.convert(qlr, [qr], label_name, red=red)
        send(
            qlr.data, printer
        )  # this is some standard code for printing with brother label printer with python,
        # red = True means that black and red printing will be done. Only for 62 label paper
        logging.info("Printed!")
def print_text():
    """
    API to print a label

    returns: JSON

    Ideas for additional URL parameters:
    - alignment
    """

    return_dict = {"success": False}

    try:
        context = get_label_context(request)
    except LookupError as e:
        return_dict["error"] = e.msg
        return return_dict

    if context["text"] is None:
        return_dict["error"] = "Please provide the text for the label"
        return return_dict

    im = create_label_im(**context)
    if DEBUG:
        im.save("sample-out.png")

    if context["kind"] == ENDLESS_LABEL:
        rotate = 0 if context["orientation"] == "standard" else 90
    elif context["kind"] in (ROUND_DIE_CUT_LABEL, DIE_CUT_LABEL):
        rotate = "auto"

    qlr = BrotherQLRaster(CONFIG["PRINTER"]["MODEL"])
    red = False
    if "red" in context["label_size"]:
        red = True
    create_label(
        qlr,
        im,
        context["label_size"],
        red=red,
        threshold=context["threshold"],
        cut=True,
        rotate=rotate,
    )

    if not DEBUG:
        try:
            be = BACKEND_CLASS(CONFIG["PRINTER"]["PRINTER"])
            be.write(qlr.data)
            be.dispose()
            del be
        except Exception as e:
            return_dict["message"] = str(e)
            logger.warning("Exception happened: %s", e)
            return return_dict

    return_dict["success"] = True
    if DEBUG:
        return_dict["data"] = str(qlr.data)
    return return_dict
def print_text():
    """
    API to print a label

    returns: JSON

    Ideas for additional URL parameters:
    - alignment
    """

    return_dict = {'success': False}

    try:
        context = get_label_context(request)
    except LookupError as e:
        return_dict['error'] = e.msg
        return return_dict

    if context['text'] is None:
        return_dict['error'] = 'Please provide the text for the label'
        return return_dict

    im = create_label_im(**context)
    if DEBUG: im.save('sample-out.png')

    if context['kind'] == ENDLESS_LABEL:
        rotate = 0 if context['orientation'] == 'standard' else 90
    elif context['kind'] in (ROUND_DIE_CUT_LABEL, DIE_CUT_LABEL):
        rotate = 'auto'

    red = False
    if context['color'] == 'redandblack':
        red = True

    qlr = BrotherQLRaster(CONFIG['PRINTER']['MODEL'])
    create_label(qlr,
                 im,
                 context['label_size'],
                 threshold=context['threshold'],
                 cut=True,
                 red=red,
                 rotate=rotate)

    if not DEBUG:
        try:
            be = BACKEND_CLASS(CONFIG['PRINTER']['PRINTER'])
            be.write(qlr.data)
            be.dispose()
            del be
        except Exception as e:
            return_dict['message'] = str(e)
            logger.warning('Exception happened: %s', e)
            return return_dict

    return_dict['success'] = True
    if DEBUG: return_dict['data'] = str(qlr.data)
    return return_dict
Beispiel #6
0
def print_image():
    """
    API to print a label

    returns: JSON

    Ideas for additional URL parameters:
    - alignment
    """

    return_dict = {'success': False}

    try:
        context = get_label_context(request)
    except LookupError as e:
        return_dict['error'] = e.msg
        return return_dict

    if not image_exists(context["file_name"]):
        return_dict['message'] = "Image not in directory"
        logger.warning('Exception happened: Image not in directory')
        return return_dict

    im = Image.open(os.path.join(IMG_DIR, context["file_name"]))

    if context['kind'] == ENDLESS_LABEL:
        rotate = 0 if context['orientation'] == 'standard' else 90
    elif context['kind'] in (ROUND_DIE_CUT_LABEL, DIE_CUT_LABEL):
        rotate = 'auto'

    qlr = BrotherQLRaster(CONFIG['PRINTER']['MODEL'])
    create_label(qlr,
                 im,
                 context['label_size'],
                 cut=True,
                 red=True if "red" in context['label_size'] else False,
                 rotate=rotate)

    if not DEBUG:
        try:
            be = BACKEND_CLASS(CONFIG['PRINTER']['PRINTER'])
            be.write(qlr.data)
            be.dispose()
            del be
        except Exception as e:
            return_dict['message'] = str(e)
            logger.warning('Exception happened: %s', e)
            return return_dict

    return_dict['success'] = True
    if DEBUG: return_dict['data'] = str(qlr.data)
    return return_dict
Beispiel #7
0
def do_print():
    """
    Receive the image from the frontend and print it
    :return: string a simple 'ok' when no exception was thrown
    """
    im = Image.open(request.files['data'])
    qlr = BrotherQLRaster(MODEL)
    create_label(qlr, im, request.form['size'], threshold=70, cut=False, rotate=0)

    # noinspection PyCallingNonCallable
    be = BACKEND_CLASS(BACKEND_STRING_DESCR)
    be.write(qlr.data)
    be.dispose()
    del be

    return 'ok'
Beispiel #8
0
def printLabel(name):
    width = 500
    height = 100

    d = Drawing(width, height)
    d.add(String(5, 5, name, fontSize=40, fontName='Helvetica'))
    #d.add(String(5, 5, name, fontSize=60, fontName='Helvetica'))

    qlr = BrotherQLRaster('QL-1050')
    #qlr = BrotherQLRaster('QL-800')
    create_label(qlr,
                 renderPM.drawToPIL(d),
                 LABEL_NAME,
                 rotate=0,
                 cut=True,
                 dpi_600=DPI_600)
    send(qlr.data, PRINTER)
Beispiel #9
0
def print_text():
    """
    API to print a label

    returns: JSON

    Ideas for additional URL parameters:
    - alignment
    """

    return_dict = {'success': False}

    try:
        context = get_label_context(request)
    except LookupError as e:
        return_dict['error'] = e.msg
        return return_dict

    if context['text'] is None:
        return_dict['error'] = 'Please provide the text for the label'
        return return_dict

    im = create_label_im(**context)
    if DEBUG: im.save('sample-out.png')

    qlr = BrotherQLRaster(MODEL)
    rotate = 0 if context['orientation'] == 'standard' else 90
    create_label(qlr, im, context['label_size'], threshold=context['threshold'], cut=True, rotate=rotate)

    if not DEBUG:
        try:
            be = BACKEND_CLASS(BACKEND_STRING_DESCR)
            be.write(qlr.data)
            be.dispose()
            del be
        except Exception as e:
            return_dict['message'] = str(e)
            logger.warning('Exception happened: %s', e)
            return return_dict

    return_dict['success'] = True
    if DEBUG: return_dict['data'] = str(qlr.data)
    return return_dict
Beispiel #10
0
    def __init__(self, picname: str) -> None:
        """
        :param picname: path to a picture to be printed
        :type picname: str

        When creating an instance of the class, it creates a task for a brother QL-800 printer to print a label with a
        qr-code passed as an argument. picname != qrpic, it contains side fields and logos (optionally)
        """
        logging.warning("Initializing printer")

        qr = Image.open(picname)

        printer = "usb://0x04f9:0x209b"  # link to device on RPI
        label_name = "62"  # that depends on paper used for printing

        logging.warning("Printing...")
        qlr = BrotherQLRaster("QL-800")
        conversion.convert(qlr, [qr], label_name, red=True)
        send(
            qlr.data, printer
        )  # this is some standard code for printing with brother label printer with python,
        # red = True means that black and red printing will be done. Only for 62 label paper
        logging.warning("Printed!")
Beispiel #11
0
    def prt(self):
        print(label_type_specs[self.size])
        if label_type_specs[self.size]['kind'] == ENDLESS_LABEL:
            rot = 0 if not self.rotated else 90
        else:
            rot = 'auto'

        if label_type_specs[self.size]['kind'] != 2:
            label_type_specs[
                self.size]['feed_margin'] = config['label']['feed_margin']

        qlr = BrotherQLRaster(config['printer']['model'])
        if config['printer']['model'] in cuttingsupport:
            logger.debug('Printer is capable of automatic cutting.')
            cutting = True
        else:
            logger.debug('Printer is not capable of automatic cutting.')
            cutting = False
        create_label(qlr,
                     self.image,
                     self.size,
                     threshold=30,
                     cut=cutting,
                     rotate=rot)
        try:
            backend_class = backend_factory(backend)['backend_class']
            be = backend_class(config['printer']['device'])
            pprint(vars(be))
            be.write(qlr.data)
            be.dispose()
            del be
            # TODO better feedback from printer
            return "alert-success", "<b>Success:</b>Label printed"
        except Exception as e:
            logger.warning("unable tp print")
            logger.warning(e)
            return "danger", "unable to print"
Beispiel #12
0
def print_text():
    """
    API to print a label

    returns: JSON

    Ideas for additional URL parameters:
    - alignment
    """

    return_dict = {'success': False}

    try:
        context = get_label_context(request)
    except LookupError as e:
        return_dict['message'] = e.msg
        return return_dict

    if not context['text'] or context['text'] is None:
        return_dict['message'] = 'Please provide the text for the label'
        return return_dict

    if not context['printer_name'] or context['printer_name'] is None:
        return_dict['message'] = 'Please select a printer'
        return return_dict

    im = create_label_im(**context)
    if DEBUG: im.save('sample-out.png')

    if context['kind'] == ENDLESS_LABEL:
        rotate = 0 if context['orientation'] == 'standard' else 90
    elif context['kind'] in (ROUND_DIE_CUT_LABEL, DIE_CUT_LABEL):
        rotate = 'auto'

    qlr = BrotherQLRaster(PRINTERS[context['printer_name']]["MODEL"])
    create_label(qlr,
                 im,
                 context['label_size'],
                 threshold=context['threshold'],
                 cut=True,
                 rotate=rotate)

    try:
        selected_backend = guess_backend(
            PRINTERS[context['printer_name']]["LOCATION"])
    except Exception as e:
        return_dict['message'] = str(e)
        return return_dict

    BACKEND_CLASS = backend_factory(selected_backend)['backend_class']

    if not DEBUG:
        try:
            be = BACKEND_CLASS(PRINTERS[context['printer_name']]["LOCATION"])
            be.write(qlr.data)
            be.dispose()
            del be
        except Exception as e:
            return_dict['message'] = str(e)
            logger.warning('Exception happened: %s', e)
            return return_dict

    return_dict['success'] = True
    if DEBUG: return_dict['data'] = str(qlr.data)
    return return_dict
Beispiel #13
0
def print_text(**data):
    global DEBUG, FONTS, DEFAULT_FONT, MODEL, BACKEND_CLASS, BACKEND_STRING_DESCR, DEFAULT_ORIENTATION, DEFAULT_LABEL_SIZE
    BACKEND_STRING_DESCR = data["printer_uri"]  # "tcp://192.168.0.10:9100"
    font_folder = "./static/fonts"
    selected_backend = guess_backend(BACKEND_STRING_DESCR)
    BACKEND_CLASS = backend_factory(selected_backend)["backend_class"]
    MODEL = data["printer_model"]  # "QL-720NW"
    DEFAULT_LABEL_SIZE = data["label_size"]  # "62x100"
    DEFAULT_ORIENTATION = data["orientation"]  # "rotated"

    FONTS = get_fonts()
    if font_folder:
        FONTS.update(get_fonts(font_folder))

    status = False

    try:
        context = get_label_context(
            data["first_name"], data["last_name"], data["company"], data["label_size"]
        )
    except LookupError as e:
        return status

    if context["name"] is None:
        return status

    if context["company"] is None:
        context["company"] = ""

    if context["last_name"] is None:
        context["name"] = context["first_name"]

    context["event_name"] = data["event_name"]
    context["logo"] = data["logo"]
    context["label_tpl"] = data["label_tpl"]
    context["ticket_type"] = data["ticket_type"]
    im = eval("create_label_im_" + data["label_size"])(**context)
    if data["debug"]:
        data["image"] = im
        try:
            im.save(
                settings.MEDIA_ROOT
                + "/cache/label-%s_%s.png" % (data["first_name"], data["last_name"])
            )
        except FileNotFoundError:
            os.mkdir(settings.MEDIA_ROOT + "/cache")
            im.save(
                settings.MEDIA_ROOT
                + "/cache/label-%s_%s.png" % (data["first_name"], data["last_name"])
            )
    else:
        qlr = BrotherQLRaster(MODEL)
        rotate = 0 if data["orientation"] == "standard" else 90
        if context["label_size"] == "62x29":
            rotate = 0
        create_label(
            qlr,
            im,
            context["label_size"],
            threshold=context["threshold"],
            cut=True,
            rotate=rotate,
        )

        try:
            be = BACKEND_CLASS(BACKEND_STRING_DESCR)
            be.write(qlr.data)
            be.dispose()
            del be
        except Exception as e:
            return status
    status = True
    return status
Beispiel #14
0
    img = Image.new('L', (696, 128), 255)

    # Add DataMatrix barcode
    code = barcode('datamatrix',
                   text,
                   options={'rows': 16, 'columns': 16},
                   margins=10)                              # type: Image
    img.paste(code.rotate(90).resize((128,128)), (0,0))

    # Add ID text
    txt = Image.new('L', (128,35), 255)
    draw = ImageDraw.Draw(txt)
    font = ImageFont.truetype("Ubuntu-Regular.ttf", 30)
    tw,th = draw.textsize(text, font)
    draw.text(((128-tw)//2, 0), text, 0, font=font)
    draw.line((0,34,128,34))
    txt = txt.rotate(90, expand=1)
    img.paste(txt, (128,0))

    img.paste(img, (128+35+15,0))
    img.paste(img, ((128+35+15)*2,0))

    # Save image
    img.save('label.bmp')

    if not TESTING:
        # Print label
        qlr = BrotherQLRaster('QL-700')
        create_label(qlr, img, '62', threshold=70, cut=True)
        printer.write(qlr.data)
Beispiel #15
0
def print_text():
    """
    API to print a label

    returns: JSON

    Ideas for additional URL parameters:
    - alignment
    """

    return_dict = {'success': False}

    try:
        context = get_label_context(request)
    except LookupError as e:
        return_dict['error'] = e.msg
        return return_dict

    if context['text'] is None:
        return_dict['error'] = 'Please provide the text for the label'
        return return_dict

    im = create_label_im(**context)
    if DEBUG:
        im.save('sample-out.png')

    if context['kind'] == ENDLESS_LABEL:
        rotate = 0 if context['orientation'] == 'standard' else 90
    elif context['kind'] in (ROUND_DIE_CUT_LABEL, DIE_CUT_LABEL):
        rotate = 'auto'

    qlr = BrotherQLRaster(CONFIG['PRINTER']['MODEL'])
    red = False
    if 'red' in context['label_size']:
        red = True

    if context['image_mode'] == 'grayscale':
        dither = True
    else:
        dither = False

    threshold = (context['image_bw_threshold'] / 255) * 100

    for cnt in range(1, context['print_count'] + 1):
        if context['cut_mode'] == 'cut':
            cut = True
        elif context['cut_mode'] == 'cut_once' and cnt == context[
                'print_count']:
            cut = True
        else:
            cut = False

        create_label(qlr,
                     im,
                     context['label_size'],
                     red=red,
                     dither=dither,
                     threshold=threshold,
                     cut=cut,
                     rotate=rotate)

    if not DEBUG:
        try:
            be = BACKEND_CLASS(CONFIG['PRINTER']['PRINTER'])
            be.write(qlr.data)
            be.dispose()
            del be
        except Exception as e:
            return_dict['message'] = str(e)
            logger.warning('Exception happened: %s', e)
            return return_dict

    return_dict['success'] = True
    if DEBUG:
        return_dict['data'] = str(qlr.data)
    return return_dict
Beispiel #16
0
def printLabel(user, eventName):
    FONT_NAME = "/usr/share/fonts/truetype/DejaVuSans.ttf"
    f17 = ImageFont.truetype(FONT_NAME, 17)
    f18 = ImageFont.truetype(FONT_NAME, 18)
    f25 = ImageFont.truetype(FONT_NAME, 25)
    f40 = ImageFont.truetype(FONT_NAME, 40)
    f80 = ImageFont.truetype(FONT_NAME, 80)
    f100 = ImageFont.truetype(FONT_NAME, 100)

    name = HumanName(user['Name'])

    ticket = user['Tickets'].split()
    if 'Abend' in user['Tickets']:
        ticket[0] += ' ' + ticket[1]

    mitarbeiter = False
    if 'Mitarbeiter' in user['Tickets']:
        mitarbeiter = True
    if 'Free' in user['Tickets']:
        mitarbeiter = True

    for i in range(2):
        img = Image.new("RGB", imgSize, fillWhite)
        draw = ImageDraw.Draw(img)

        printCenter(draw, 50, (name.first.capitalize() + ' ' + name.middle.capitalize()).strip(), f100)
        printCenter(draw, 170, name.last.capitalize(), f40)

        if i == 0:
            if mitarbeiter:
                printCenter(draw, 240, "Mitarbeiter", f80)

            printCenter(draw, 350, ticket[0] + ' (' + user['order'] + ')', f40)
            printCenter(draw, 400, eventName, f40)

            if 'Alter' in user:
                printCenter(draw, 450, "Alter: " + str(user['Alter']), f25)

            if 'Seminare und Workshops' in user:
                seminar = user['Seminare und Workshops'].split('(')
                printCenter(draw, 485, seminar[0], f25)
        else:
            text = """
Samstag
11.30 Uhr - “Zwischen Heimweh und Fernsucht”
13.00 Uhr - Mittagessen
14.30 Uhr - Seminare & Workshops
16.30 Uhr - “We will block you”
18.00 Uhr - Abendessen
20.00 Uhr - “Comming Home”
22.00 Uhr - Latenightangebote & Konzerte"""
            printLeft(draw, 0, 240, text, f17)

            text = """
Sonntag
08.00 Uhr - Frühstück
09.30 Uhr - “Dieser Weg wird kein Leichter sein”
12.00 Uhr - Mittagessen
13.30 Uhr - “Ist herzlich Willkommen übertrieben?”
14.30 Uhr - Abreise

Einlass jeweils 15 Minuten vor Veranstaltungsbeginn"""
            printLeft(draw, 450, 240, text, f17)

            text = """
Solltest du Erste Hilfe benötigen, erreichst du das Connect-Notfall-Team unter 
der Telefonnummer 0170 - 27 65 185 oder du meldest dich am Infopoint."""

            printLeft(draw, 0, 450, text, f18)

        img.save('tmp.png')

        qlr = BrotherQLRaster(CONFIG['printer'])
        qlr.exception_on_warning = True
        convert(qlr, ['tmp.png'], '54', cut=True, dither=False, compress=True, red=False, dpi_600=False, hq=True, rotate=90)
        send(instructions=qlr.data, printer_identifier=CONFIG['identifier'], backend_identifier=CONFIG['backend'], blocking=True)
Beispiel #17
0
def print_image():
    return_dict = {'success': False}

    logger.warning(request)

    try:
        #context = get_label_context(request)
        context = {}
        logger.warning(context)
    except LookupError as e:
        return_dict['error'] = e.msg
        return return_dict

    import requests
    from PIL import Image, ImageOps
    from io import BytesIO
    import os

    # load image from the upload request ..

    print('file names:')
    for k in request.files.keys():
        print(k)

    upload = request.files.get('photos')
    name = upload.filename
    image_name = 'last-image-%s' % name
    if (os.path.exists(image_name)):
        os.remove(image_name)
    upload.save(image_name)

    im = Image.open(image_name)

    width, height = im.size

    i2 = Image.new('RGB', (696, height), '#ffffff')

    context['width'] = 696
    context['height'] = height

    context['label_size'] = "62"
    context['threshold'] = 70
    rotate = 0

    print('image height: %d' % height)

    qlr = BrotherQLRaster(CONFIG['PRINTER']['MODEL'])
    create_label(qlr,
                 im,
                 context['label_size'],
                 threshold=context['threshold'],
                 cut=True,
                 rotate=rotate)

    if not DEBUG:
        try:
            be = BACKEND_CLASS(CONFIG['PRINTER']['PRINTER'])
            be.write(qlr.data)
            be.dispose()
            del be
        except Exception as e:
            return_dict['message'] = str(e)
            logger.warning('Exception happened: %s', e)
            return return_dict

    return_dict['success'] = True
    if DEBUG: return_dict['data'] = str(qlr.data)
    return return_dict
Beispiel #18
0
def print_text(**data):
    global DEBUG, FONTS, DEFAULT_FONT, MODEL, BACKEND_CLASS, BACKEND_STRING_DESCR, DEFAULT_ORIENTATION, DEFAULT_LABEL_SIZE
    BACKEND_STRING_DESCR = data['printer_uri']  # "tcp://192.168.0.10:9100"
    font_folder = "./static/fonts"
    selected_backend = guess_backend(BACKEND_STRING_DESCR)
    BACKEND_CLASS = backend_factory(selected_backend)['backend_class']
    MODEL = data['printer_model']  # "QL-720NW"
    DEFAULT_LABEL_SIZE = data['label_size']  # "62x100"
    DEFAULT_ORIENTATION = data['orientation']  # "rotated"

    FONTS = get_fonts()
    if font_folder:
        FONTS.update(get_fonts(font_folder))

    status = False

    try:
        context = get_label_context(data['first_name'], data['last_name'],
                                    data['company'], data['label_size'])
    except LookupError as e:
        return status

    if context['name'] is None:
        return status

    if context['company'] is None:
        context['company'] = ''

    if context['last_name'] is None:
        context['name'] = context['first_name']

    context['event_name'] = data['event_name']
    context['logo'] = data['logo']
    context['label_tpl'] = data['label_tpl']
    context['ticket_type'] = data['ticket_type']
    im = eval('create_label_im_' + data['label_size'])(**context)
    if data['debug']:
        data['image'] = im
        try:
            im.save(settings.MEDIA_ROOT + '/cache/label-%s_%s.png' %
                    (data['first_name'], data['last_name']))
        except FileNotFoundError:
            os.mkdir(settings.MEDIA_ROOT + '/cache')
            im.save(settings.MEDIA_ROOT + '/cache/label-%s_%s.png' %
                    (data['first_name'], data['last_name']))
    else:
        qlr = BrotherQLRaster(MODEL)
        rotate = 0 if data['orientation'] == 'standard' else 90
        if context['label_size'] == '62x29':
            rotate = 0
        create_label(qlr,
                     im,
                     context['label_size'],
                     threshold=context['threshold'],
                     cut=True,
                     rotate=rotate)

        try:
            be = BACKEND_CLASS(BACKEND_STRING_DESCR)
            be.write(qlr.data)
            be.dispose()
            del be
        except Exception as e:
            return status
    status = True
    return status
Beispiel #19
0
def print_qrcodetracker():
    return_dict = {'success': False}

    try:
        context = get_label_context(request)
        logger.warning(context)
    except LookupError as e:
        return_dict['error'] = e.msg
        return return_dict

    import requests
    from PIL import Image, ImageOps
    from io import BytesIO

    r = requests.get('https://api.qrserver.com/v1/create-qr-code/',
                     params={
                         'data': context['qr'],
                         'size':
                         '%sx%s' % (context['qrsize'], context['qrsize'])
                     })
    logger.warning('REQUEST URL: %s' % (r.url))
    logger.warning(r)
    logger.warning('contents:')
    logger.warning(r.content)
    im = Image.open(BytesIO(r.content))

    im = im.convert('RGB')
    im.save('last-qrcode.png')

    if context['kind'] == ENDLESS_LABEL:
        rotate = 0 if context['orientation'] == 'standard' else 90
    elif context['kind'] in (ROUND_DIE_CUT_LABEL, DIE_CUT_LABEL):
        rotate = 'auto'

    if rotate == 0:
        i2 = Image.new('RGB', (696, context['qrsize']), '#ffffff')
    else:
        i2 = Image.new('RGB', (context['qrsize'], 696), '#ffffff')


#    i2 = ImageOps.expand(im, border=300, fill='#ffffff')
#    im = i2.crop((0,300, 696,300+context['qrsize']))

# create multiple qrcodes on the label ...
    xoffset = 0

    im3 = create_label_im(**context)

    im33 = im3.convert('RGB')
    im33.save('last-text-0.png')

    i2.paste(im3, (0, 0))

    im33 = i2.convert('RGB')
    im33.save('last-text-1.png')

    i2.paste(im, (0, 100))

    im33 = i2.convert('RGB')
    im33.save('last-text-2.png')

    context['width'] = 696
    context['height'] = context['qrsize']

    qlr = BrotherQLRaster(CONFIG['PRINTER']['MODEL'])
    create_label(qlr,
                 i2,
                 context['label_size'],
                 threshold=context['threshold'],
                 cut=True,
                 rotate=rotate)

    if not DEBUG:
        try:
            be = BACKEND_CLASS(CONFIG['PRINTER']['PRINTER'])
            be.write(qlr.data)
            be.dispose()
            del be
        except Exception as e:
            return_dict['message'] = str(e)
            logger.warning('Exception happened: %s', e)
            return return_dict

    return_dict['success'] = True
    if DEBUG: return_dict['data'] = str(qlr.data)
    return return_dict