Thu Mar 22, 2018 4:12 am
Login Register Lost Password? Contact Us

Returning png data from embedded python

Comments and questions related to the Enterprise Control Language

Tue Dec 05, 2017 2:24 pm Change Time Zone

I'm trying to return an image from my embedded python. Here is my code:
Code: Select all
IMPORT Python;
DATA ReadAndOutputPngFile() := EMBED(Python)
    from imageio import imread
    import numpy as np

    png=imread('class%s-maximal-image.png' % (output_index))
    return png


When I attempt to execute this, I get the following error message:
Code: Select all
Error: Error: 0: pyembed: type mismatch - bytearray expected

What must my return data type?
Posts: 240
Joined: Mon May 07, 2012 6:23 pm

Wed Dec 06, 2017 1:48 pm Change Time Zone

Hi Tim,

I do not work with Python, but I found some interesting links:

I guess the compiler doesn't like DATA as the return value, maybe try a SET OF UNSIGNED1 ?


Community Advisory Board Member
Community Advisory Board Member
Posts: 975
Joined: Wed Jun 29, 2011 7:13 pm

Tue Dec 19, 2017 4:31 pm Change Time Zone

With the help of Gordon Smith, I got this to work. But I had to change to platform 6.2.16-1. The following code displays the image as output to the workunit:
Code: Select all
IMPORT Python;
STRING ReadAndOutputPngFile() := EMBED(Python)
    import base64
    encoded = base64.b64encode(open(pngfile, "rb").read())
    return encoded

OUTPUT(DATASET([{'<img src="data:image/png;base64,' + img + '" />'}], {STRING base64Image__html}));
Posts: 240
Joined: Mon May 07, 2012 6:23 pm

Return to ECL

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest