cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Register to attend Discovery Summit 2025 Online: Early Users Edition, Sept. 24-25.
  • New JMP features coming to desktops everywhere this September. Sign up to learn more at jmp.com/launch.
Choose Language Hide Translation Bar

Extract String Representation of an Image

Is there a better way to get the string from New Image() than converting the expression to a string and extracting?  It just feels sloppy.  Arg() doesn't work with "Picture" objects.

 

Names Default to Here ( 1 );
g = New Image( Char To Blob( "blahblahblob", "base64compressed" ) );
f = Substr( Char( g ), Contains( Char( g ), "\!"") + 1, Contains( Char( g ), "\!", \!"base64" ) - ( Contains( Char( g ), "\!"") + 1 ) );
1 ACCEPTED SOLUTION

Accepted Solutions

Re: Extract String Representation of an Image

I figured out what to do.  Here I have images in my data table dt.  Pulling the value of the cell created a picture object, but I found a way around that.  I kept trying to use expressions and failing.  Then I remembered that parsing a string has essentially the same effect as defining an expression.  Now I can fairly cleanly send images from JMP to Python.

 

Names Default to Here ( 1 );
r = Parse( Char( dt:Image[11] ) );
f = Arg( Arg( r, 1 ) );
h = Encode64 Blob( Char to Blob( f, "base64compressed" ) );
Python Submit( Eval Insert( "\[
import base64
import io
from PIL import Image
pic = '''☺h☺'''
imgdata = base64.standard_b64decode(pic)
img = Image.open(io.BytesIO(imgdata))
img.show()
]\", "☺"
) );

 

View solution in original post

2 REPLIES 2

Re: Extract String Representation of an Image

I figured out what to do.  Here I have images in my data table dt.  Pulling the value of the cell created a picture object, but I found a way around that.  I kept trying to use expressions and failing.  Then I remembered that parsing a string has essentially the same effect as defining an expression.  Now I can fairly cleanly send images from JMP to Python.

 

Names Default to Here ( 1 );
r = Parse( Char( dt:Image[11] ) );
f = Arg( Arg( r, 1 ) );
h = Encode64 Blob( Char to Blob( f, "base64compressed" ) );
Python Submit( Eval Insert( "\[
import base64
import io
from PIL import Image
pic = '''☺h☺'''
imgdata = base64.standard_b64decode(pic)
img = Image.open(io.BytesIO(imgdata))
img.show()
]\", "☺"
) );

 

jthi
Super User

Re: Extract String Representation of an Image

I did something similar here HTML with Embedded Images (see my reply) when I wanted a static .html without the gfx folder JMP usually creates.

View more...
Names Default To Here(1);
cur_pic = New Image("$SAMPLE_IMAGES/windmap.png");
base64compressed_str = Arg(Arg(parse(Char(cur_pic)), 1), 1);
base64_str = Encode64 Blob(Gzip Uncompress(Char To Blob(base64compressed_str, "base64compressed")));

To my understanding, this should get easier for JMP's Python integration in JMP19. 

-Jarmo

Recommended Articles