# Rendering PNG data in perspective

**URL:** <https://forum.inductiveautomation.com/t/rendering-png-data-in-perspective/85096>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [February 1, 2024, 3:33pm UTC](https://forum.inductiveautomation.com/t/rendering-png-data-in-perspective/85096 "2024-02-01T15:33:19Z")\
**Posts on this page:** 14\
**Page:** 2

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 17, 2024, 2:55pm UTC](https://forum.inductiveautomation.com/t/rendering-png-data-in-perspective/85096/21 "2024-04-17T14:55:38Z")

</div>

> [@Kevin.Herron](#):
>
> getting their code from ChatGPT

Heh. There's that.

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

---

<div class="post-metadata">

**Author:** ![jakned](https://avatars.discourse-cdn.com/v4/letter/j/4da419/32.png) [@jakned](https://forum.inductiveautomation.com/u/jakned)\
**Post date:** [April 17, 2024, 3:20pm UTC](https://forum.inductiveautomation.com/t/rendering-png-data-in-perspective/85096/22 "2024-04-17T15:20:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jakned](https://avatars.discourse-cdn.com/v4/letter/j/4da419/32.png) [@jakned](https://forum.inductiveautomation.com/u/jakned)\
**Post date:** [April 17, 2024, 3:20pm UTC](https://forum.inductiveautomation.com/t/rendering-png-data-in-perspective/85096/23 "2024-04-17T15:20:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 17, 2024, 3:26pm UTC](https://forum.inductiveautomation.com/t/rendering-png-data-in-perspective/85096/24 "2024-04-17T15:26:29Z")

</div>

> [@jakned](#):
>
> didnt expect anyone

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.

---

<div class="post-metadata">

**Author:** ![jakned](https://avatars.discourse-cdn.com/v4/letter/j/4da419/32.png) [@jakned](https://forum.inductiveautomation.com/u/jakned)\
**Post date:** [April 17, 2024, 3:36pm UTC](https://forum.inductiveautomation.com/t/rendering-png-data-in-perspective/85096/25 "2024-04-17T15:36:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jakned](https://avatars.discourse-cdn.com/v4/letter/j/4da419/32.png) [@jakned](https://forum.inductiveautomation.com/u/jakned)\
**Post date:** [April 17, 2024, 3:38pm UTC](https://forum.inductiveautomation.com/t/rendering-png-data-in-perspective/85096/26 "2024-04-17T15:38:23Z")

</div>

Are changes like this announced in release notes?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [April 17, 2024, 3:40pm UTC](https://forum.inductiveautomation.com/t/rendering-png-data-in-perspective/85096/27 "2024-04-17T15:40:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jakned](https://avatars.discourse-cdn.com/v4/letter/j/4da419/32.png) [@jakned](https://forum.inductiveautomation.com/u/jakned)\
**Post date:** [November 7, 2024, 1:41pm UTC](https://forum.inductiveautomation.com/t/rendering-png-data-in-perspective/85096/28 "2024-11-07T13:41:27Z")

</div>

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

```python
"""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)

```

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [November 7, 2024, 3:06pm UTC](https://forum.inductiveautomation.com/t/rendering-png-data-in-perspective/85096/29 "2024-11-07T15:06:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Felipe\_CRM](https://avatars.discourse-cdn.com/v4/letter/f/dfb087/32.png) [@Felipe\_CRM](https://forum.inductiveautomation.com/u/Felipe_CRM)\
**Post date:** [November 7, 2024, 3:26pm UTC](https://forum.inductiveautomation.com/t/rendering-png-data-in-perspective/85096/30 "2024-11-07T15:26:08Z")

</div>

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](https://github.com/w3blogfr/zebra-zpl/blob/607d5049763b6bc9366e8c0a42024be345037149/src/main/java/fr/w3blog/zpl/model/ZebraLabel.java#L222) that includes a `getImagePreview()` method to render a ZPL label as a `BufferedImage`.

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [November 7, 2024, 3:44pm UTC](https://forum.inductiveautomation.com/t/rendering-png-data-in-perspective/85096/31 "2024-11-07T15:44:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 7, 2024, 3:49pm UTC](https://forum.inductiveautomation.com/t/rendering-png-data-in-perspective/85096/32 "2024-11-07T15:49:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [November 7, 2024, 4:07pm UTC](https://forum.inductiveautomation.com/t/rendering-png-data-in-perspective/85096/33 "2024-11-07T16:07:14Z")

</div>

> [@victordcq](#):
>
> Using this thrid party website to convert zpl to pdf seems not very safe.

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

> **[Labelary FAQ](https://labelary.com/faq.html#offline)**
>
> Frequently asked questions relating to the Labelary ZPL rendering engine.

I would definitely at least _look into_ that if I were doing this in production.

---

<div class="post-metadata">

**Author:** ![Austin\_Li](https://avatars.discourse-cdn.com/v4/letter/a/ea666f/32.png) [@Austin\_Li](https://forum.inductiveautomation.com/u/Austin_Li)\
**Post date:** [December 24, 2025, 7:22pm UTC](https://forum.inductiveautomation.com/t/rendering-png-data-in-perspective/85096/34 "2025-12-24T19:22:43Z")

</div>

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](https://inductiveautomation.com/exchange/2884/overview)

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](https://forum.inductiveautomation.com/t/printing-barcode-to-zebra-printer/8957/8)

Thanks all!

[Previous page](https://forum.inductiveautomation.com/t/rendering-png-data-in-perspective/85096.md?page=1)
