Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Cannot parse (BASE64) into a raw IMAGE (TSPL) #1264

Open
Madcheese101 opened this issue May 4, 2024 · 6 comments
Open

Error: Cannot parse (BASE64) into a raw IMAGE (TSPL) #1264

Madcheese101 opened this issue May 4, 2024 · 6 comments
Assignees
Labels

Comments

@Madcheese101
Copy link

Your package is included with the frappe bench framework, before running npm update qz-tray it used to result in a similar error but with my website link included before the base64 string

I hope that you guide me on this matter because I am lost in this one. My Label Printer does not support the Arabic language and the only option I could think of was to make an image of that and pass it to the printer.

In this example, I am only testing passing the base64 string of an image saved in a memory object; A real use case would be sending a command that contains the barcode and its number using the TSPL commands for it, and then under it, I would like to write text in Arabic (can only be done using the TSPL Bitmap command)

note: English text can be passed to the printer perfectly fine using the TSPL Text command

Python Code:

@frappe.whitelist()
def create_bitmap_from_text(text, font_size=20):
    # Create an image with a white background
    img = Image.new("RGB", (500, 200), color="white")
    draw = ImageDraw.Draw(img)

    # Load a font (you can specify a different font path)
    font_path = "/usr/share/fonts/truetype/ubuntu/UbuntuMono-R.ttf"
    font = ImageFont.truetype(font_path, font_size)

    multiline_text = """First Line.
second line."""

    draw.multiline_text((20, 20), multiline_text, fill="black", font=font, spacing=4, align="left")

    temp_img = io.BytesIO()

    # Save the image to the BytesIO object in PNG format
    img.save(temp_img, format='PNG')

    # Convert the BytesIO object's content to a byte string
    image_data_bytes = temp_img.getvalue()

    # Encode the image data as a Base64 string
    encoded_image = base64.b64encode(image_data_bytes).decode('utf-8')
    return encoded_image 

JS Code

frappe.call({
        method: 'renting_services.utils.utils.create_bitmap_from_text',
        freeze: true,
        callback: function(r) {
            if (r.message){
                console.log(r.message);
            }
            frappe.ui.form.qz_connect()
            .then(function () {
                var str_ = ["SIZE 76 mm, 101.6 mm\n",
                "DIRECTION 0,0\n",
                "REFERENCE 0,0\n",
                "OFFSET 0 mm\n",
                "SET PEEL OFF\n",
                "SET CUTTER OFF\n",
                "SET TEAR ON\n",
                "CLS\n",
                "BITMAP 437,743,18,40,1,",
                {
                    type: 'raw', format: 'image', flavor: 'base64',
                    data: r.message, 
                    options: { language: "tspl-ez" },
                },
                '\n',
                'PRINT 1,1\n'
            ]
                var config = qz.configs.create("Xprinter XP-365B");
                var printData = [
                    { type: 'pixel', format: 'image', flavor: 'base64', data: r.message}
                ];
                return qz.print(config, str_);
            })
            .then(frappe.ui.form.qz_success)
            .catch(err => {
                frappe.ui.form.qz_fail(err);
                console.log(err)
            });
        }
    });

ERROR RESULT:


QZ Tray Failed: Error: Cannot parse (BASE64)iVBORw0KGgoAAAANSUhEUgAAAfQAAADICAIAAACRe4S/AAAK+0lEQVR4nO3dS2xUZR/A4VNxerGgIIUWIRqgKhHUIiBVSYw3ShcQowuNxCvRBXjDQKILXQDGGAwsTAoujMYY1BhJlEQKYiKSII1YLZfEBZUQQOgFVJBbVeZbnHzzTVop5Wu5+Pd5FoSe95wz78zi19Mz7bwF2Ww2ASCWi873BADoe+IOEJC4AwQk7gABiTtAQOIOEJC4AwQk7gABiTtAQOIOEJC4AwQk7gABiTtAQOIOEJC4AwQk7gABiTtAQOIOEJC4AwQk7gABiTtAQOIOEJC4AwQk7gAB9TbuP/zwQ0EXY8aMye3w559/Tpw48fLLL9+wYUMvH6urWbNmTZo06UyPSuf8xhtvnGqHszpngHPgrF+5Z7PZ3L99bvv27b/88kufn/aszhngHLi4T86yePHiefPm/e1QJpPZvHlznzzKOfNPnDNAvrN75V5WVpa7V7N8+fKuO7z33nsPPvjgNddcM2jQoEwmM2TIkPnz5+dGV69ePWXKlAEDBhQVFQ0fPnzq1Kn79u1Lh+6+++6CgoKGhobm5ubcQ1RXV5/tOa9YseKOO+4YMWJEcXFxeXl5bW3t999/n7/Djz/++MADDwwePHjAgAFVVVXLli3766+/ej8rgDPSN1fu/7cFCxY0Nzfnvmxvb8+lcMuWLffee29HR0f65c8//9za2jpo0KDzMMs8Gzdu/Oqrr9L/t7a21tfXf/3111u3bh01alSSJI2Njbfffvvvv/+e7tDU1DR79uyffvpp8eLF52vCwL9T31y5z58/P/8N1dw9jfb29mw22/3bkmPGjNm6devhw4ez2Ww2m12yZEm6/Ysvvujo6Hj77bePHDmSDv3xxx/FxcXp6Lp167LZ7OTJk0ePHp39r02bNvX+ufRkztu2bevo6NizZ89999139OjRFStWpNtnz549fPjwtWvX/vrrr8ePH29sbLzuuuveeuutkydP9n5iAD13nq/ckyS57LLLxo0b13V7uvHpp5/++OOPa2pqHnrooaFDh57z2f298vLyTCYzfPjwpUuXrly5cufOnUmStLS0NDQ0JEkyderUTvsfPHiwrKzsPEwU+Lfqmyv3xYsXZ/NMnDix9+esqal59913S0pK6uvr586de9VVVy1cuPBC+w2WESNGJEly4sSJJElaWlqSJHn++eezXSg7cI6diz9iKigoSJIkdye65x599NE9e/Z88MEHjz/++MCBA1955ZXcTZvcmdOw9rkezvmii/73Ag4ZMiRJklWrVh07duxsTAmg585F3AcPHpwkycqVK9vb23t+VF1d3bPPPrtjx47777+/rq4uva/d1NTU6cx79+5dtWpV7n3X8zjnYcOG3XTTTc3NzdOnT29oaDhy5Mjf7rZr166rr7561KhR+e8kA/StcxH3UaNGVVRUfPPNN0OGDOn096vdaGpqevPNN2+44YbCwsKSkpI777wzSZKampr8faZMmZLNZmfMmFFUVNTzM6c6vQmc/z7w/z3nurq60tLSL7/8srq6un///ulpP/vss/x9Pv/88x07duzcuXPVqlU9ny3AGTkXcS8sLPzoo49uvPHGTCYzePDgHt6RnzNnzsMPPzxy5MjCwsLS0tIJEyYsX7585syZ+fs888wzs2bNGjp0aL9+/crKyiZPnnx+5zx58uTGxsZHHnnkiiuuyGQy5eXlt912W/pDQE5tbW1lZeXIkSOnT5/eV7MF6KTgQnuLEoDe86mQAAGJO0BA4g4QkLgDBCTuAAGJO0BA/4q4Hzp0qKqq6lTLiXRy2s+gB7jw/Svi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xcVXXnnllClT0tEJEyasX7/+rrvuKi0tLS0tveeee9avXz9+/PiezGr8+PEbN26cMWPGwIED+/XrN2jQoOrq6tyZe6KgoODDDz+sqqrKZDJlZWWdFsi2fDZwgbNANkBAPlsGICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdICBxBwhI3AECEneAgMQdIKD/AF0hV7GlMWv9AAAAAElFTkSuQmCC 
into a raw IMAGE command: UNKNOWN image conversion is not yet supported.

@Madcheese101 Madcheese101 changed the title Error: Cannot parse (BASE64) into a raw IMAGE command: UNKNOWN image conversion is not yet supported. Error: Cannot parse (BASE64) into a raw IMAGE (TSPL) May 4, 2024
@Madcheese101
Copy link
Author

Madcheese101 commented May 4, 2024

if this is not possible using the current version of the package, can you please guide me to the right direction?

When using the Seagull Bartender Program, it prints successfully and the print command looks like this:

SIZE 52.7 mm, 28.9 mm
DIRECTION 0,0
REFERENCE 0,0
OFFSET 0 mm
SET PEEL OFF
SET CUTTER OFF
SET TEAR ON
CLS
BITMAP 127,30,20,40,1,ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿïü ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÃø ?ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿûÁà��ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿðƒÀÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿðC�ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿà÷ƒÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿðÿ�ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿýÿ�ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿþ�ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿþ?ÿÿ�ü    ?À �ÿð?À   ?ÿÿ ð    �  �ÿð�    �ÿÿ      �  �ÿð�    �ÿÿ         �ÿð     �ÿÿ��ø�ÿñ€��Ïÿñ€��çþ�ÿÿ� þ ÿñà~�ïÿñà~�çþ?ÿÿ��ÿ�ÿøøþ�ÿÿøøþ�çþ?ÿÿ�Ÿÿ€�øùþ�ÿÿøùþ�çþ�ÿÿ‡�ÿà�øqþ�ÿÿøqþ?ãþ�ÿÿÆ?ÿð |cþ?ÿÿücþ?ãÿ�ÿÿà�ÿø þ ÿ?ÿÿþ þ�áÿ ÿÿàÿÿþ�þ�ÿ?ÿÿþ�þ�àÿ�ÿÿóÿÿÿƒÿ?ÿ�ÿÿÿ?ÿ�ðÿÏÿÿÿÿÿÿÿÿÿÿ�ÿÿÿÿÿ�ñÿïÿÿÿÿÿÿÿÿÿÿ‡ÿÿÿÿÿŸùÿÿÿÿÿÿÿÿÿÿÿÿÃÿÿÿÿÿßýÿÿÿÿÿÿÿÿÿÿÿÿÃÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿãÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿûÿÿÿÿÿßÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ‡ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿƒÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ‡ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿïÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
BARCODE 323,200,"128M",78,0,180,3,6,"!10512345678"
CODEPAGE 1252
TEXT 269,114,"3",180,1,1,"12345678"
PRINT 1,1

the result looks like this:
image

what do I need to do to convert a (PIL image object)/Image to get a command string like this?

@tresf
Copy link
Contributor

tresf commented May 5, 2024

options: { language: "tspl-ez" },

TSPL-EZ isn't an image format, but rather a compatibility to allow certain printer firmwares to emulate EPL/ZPL. Please specify one of those instead.

Valid options are:

zpl
epl
cpcl
escpos
evolis
sbpl
pgl

@tresf tresf added the support label May 5, 2024
@tresf tresf self-assigned this May 5, 2024
@tresf
Copy link
Contributor

tresf commented May 5, 2024

When using the Seagull Bartender Program, it prints successfully and the print command looks like this:

BITMAP 127,30,20,40,1, ...
...

The BITMAP command is part of the TSPL programming language. We haven't yet added support for this into QZ Tray.

  • We'd accept a PR which introduces this feature
  • You may -- if you wish -- prepare this data on your end
  • We may be able to add support in a future version of QZ Tray
  • In the meantime if you're OK using emulation through the firmware, EPL or ZPL may work with the current version of QZ Tray

The TSPL BITMAP command is described here:

image image

Adding support should be trivial because we already use a similar technique for other languages.

@Madcheese101
Copy link
Author

would you mind pointing me to where that code that gets the image data to the printing code result?

@tresf
Copy link
Contributor

tresf commented May 5, 2024

Sure:

ZPL(false, true, 203, "ZPL", "ZPL2", "ZPLII", "ZEBRA"),

@tresf
Copy link
Contributor

tresf commented May 5, 2024

As well as here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants