Fri Aug 17, 2018 10:38 pm
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: 250
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: 250
Joined: Mon May 07, 2012 6:23 pm

Return to ECL

Who is online

Users browsing this forum: No registered users and 1 guest