cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
djhanson
Level V

Can JSL do a base64 conversion?

Hi, is JSL capable of doing a base64 conversion of an image file?  (i.e. read in an image file like a .PNG and output its equivalent base64 text)

 

thanks, DJ

9 REPLIES 9

Re: Can JSL do a base64 conversion?

In JMP, select Help > JMP Help. Then search for Base64. Pops right up!

djhanson
Level V

Re: Can JSL do a base64 conversion?

Oddly enough, my JMP (12.2.0) Help menu doesn't show any references to Base64.  (search seems to be indexed too)  Are there references to it perhaps in a later version of JMP?  DJ

Re: Can JSL do a base64 conversion?

I used the current JMP 14.0 version. I confirmed that it is not provided by JMP 12.2.

Re: Can JSL do a base64 conversion?

I apologize for mis-reading your request. The Base64 conversion capability comes with the Load Text File() function. You can specify a BLOB option with a Base64Compressed toggle (on|off). I cannot find anything about saving such a format.

You might be able to use the JMP integration with R, Python, or MATLAB if they support this conversion.

djhanson
Level V

Re: Can JSL do a base64 conversion?

thanks Mark!

 

Dumb question on my part:  I suppose blob to char() can't somehow do this?  For example:
x=blob to char("c:\myfolder\myfile.PNG","base64compressed");  and then the magic, somehow be able to save x as this format.

 

I'm only asking this from reading John Ponte's interesting blog where he appeared to use char to blob() to read in a PNG as a base64 format:  (so my question is like the inverse of this of course)

https://community.jmp.com/t5/JMP-Blog/Embedding-images-in-JSL-scripts/ba-p/30080

 

Then I see that JSL has a encode64 double() command, but perhaps this isn't enough here to do an image file conversion.

 

thanks, DJ

JohnPonte
Staff (Retired)

Re: Can JSL do a base64 conversion?

When you read in an image in JSL it will show the image in the log as the base64 compressed text string. Try doing this to see the base64 representation:

 

 

img = newImage("$SAMPLE_IMAGES/windmap.png");
show(img);

 

Ironically, I don't see a way to save that string other than cut & paste it from the log. 

 

Hope this helps,

John Ponte

 

djhanson
Level V

Re: Can JSL do a base64 conversion?

Thanks All.  I eventually found a Python script to convert image files to base64.  Here's a snippet if it helps someone in the future, works quite well and very simplistic:
Python code:


import base64
with open('C:/temp/myimage.png', 'rb') as x1, open('C:/temp/myimagebase64.txt', 'w') as x2:
    base64.encode(x1, x2)

vince_faller
Super User (Alumni)

Re: Can JSL do a base64 conversion?

if you can do the base64 there, couldn't you just do 

 

Names default to here(1);
txt = log capture(
	img = newImage("$SAMPLE_IMAGES/windmap.png");
	print(img);
);
raw_string = Arg(Arg(parse(txt), 1), 1);
Vince Faller - Predictum
Craige_Hales
Super User

Re: Can JSL do a base64 conversion?

If you found this, you are looking for the Encode64Blob or Decode64Blob functions, see the scripting index.

Craige