Heh. There's that.
I have to admit that I'm not motivated to help people who post untested code from any LLM.
Heh. There's that.
I have to admit that I'm not motivated to help people who post untested code from any LLM.
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.
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.
I created a project recently on the Ignition Exchange that has some scripting for converting the image returned by the Labelary API into a base64-encoded image for use directly with the Perspective Image component (no external libraries needed). Find it at Ignition Exchange | Inductive Automation
It also has some experimental backup print preview methods that I put together with the native (but ancient) java.awt library and some classes describing common ZPL functions. This serves as an offline backup to the Labelary API (can test by turning off your ignition computer wifi). Iām not the best programmer (very self-taught) and it could definitely use some work, so Iām looking for feedback if anyone is interested in helping me improve it.
The project is intended to be paired with a database for label storage and the Zebra Designer 3 program for label design. It also uses some code posted here to actually physically print labels. Printing barcode to Zebra printer - #8 by ntheuer
Thanks all!