cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • New to JMP? Join us Sept. 23-24 for the Early User Edition of Discovery Summit, tailor-made for new users. Register now for free!
  • Your voice matters! Tell us how you prefer to receive JMP updates, so we can tailor our communication to your needs. Take short survey.
  • See how to access JMP Marketplace - and - find, create & share add-ins to extend your JMP. Watch video.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
mmarchandFSLR
Level VI

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
mmarchandFSLR
Level VI

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
mmarchandFSLR
Level VI

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