Rendering PNG data in perspective

Heh. There's that.

I have to admit that I'm not motivated to help people who post untested code from any LLM.

1 Like

I did some minor adjustments to the GPT code to make it work. The result was as expected when run in script console.

Honestly I didnt expect anyone to respond to that and roast it.

Some of us read everything here. Posting something, even without a question, is an invitation to be critiqued. In part to avoid a bunch of complaints from others running with poor ideas.

It was probably deserved. I didnt ask for help, still learned something.

Are changes like this announced in release notes?

No, not usually, although I think at times we have announced dependency updates, usually when they're being flagged by security software for existing CVEs.

I didn't mean to suggest this will happen or regularly happens, just that it's a possibility.

Yet another solution I came up with. This time using system.net.httpClient as recommended.

"""Module for interacting with the Labelary API."""

from java.net.http import HttpClient
from java.util import Base64

API = "http://api.labelary.com/v1"
ALLOWED_DPMM = (6, 8, 12, 24)
MAX_SIZE_INCH = 15


def get_label_image(client, zpl, width, height, dpmm, index=0):
    # type: (HttpClient, str, int, int, int, int) -> str
    """Get label image from Labelary API as Base64 string."""
    if dpmm not in ALLOWED_DPMM:
        raise ValueError("Invalid dpmm value. Allowed values: {}".format(ALLOWED_DPMM))

    if width <= 0 or height <= 0:
        raise ValueError("Invalid label size. Width and height must be greater than 0.")

    if width > MAX_SIZE_INCH or height > MAX_SIZE_INCH:
        raise ValueError(
            "Invalid label size. Max size is {}x{} inches.".format(
                MAX_SIZE_INCH, MAX_SIZE_INCH
            )
        )

    url = "{}/printers/{}dpmm/labels/{}x{}/{}/".format(API, dpmm, width, height, index)
    response = client.post(
        url,
        data=zpl,
        headers={
            "Accept": "image/png",
            "Content-Type": "application/x-www-form-urlencoded",
        },
    )

    if response.clientError:
        raise ValueError("Invalid request. {}".format(response.text))

    bytes = response.getBody()

    return Base64.getEncoder().encodeToString(bytes)

Using this thrid party website to convert zpl to pdf seems not very safe.

It shouldnt be to hard to convert them yourself. ZPL is basically paints itself

If you don't want to rely on a third-party service but also don't want to write your own ZPL rendering library, a quick search has uncovered this open-source (MIT license) Java library that includes a getImagePreview() method to render a ZPL label as a BufferedImage.

2 Likes

Im actually surprised it seems quite hard to find converters for zpl (especially to be browser compatible).
Its not like its very complex, yet noone has seem to made converters yet.

I may have to package that up in my Integration Toolkit for use in any scope.

Looks like for $$$ you can self-host:

I would definitely at least look into that if I were doing this in production.

1 Like