I am building a library of functions that I would like to distribute as a single JSL file. But some of my functions reference image files. In this blog post I will explain the process I use for serialising the image file so that it can be embedded directly into my JSL script.
Here is one of my functions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
Assert = function({condition,title,msg,doThrow=1}, {default local}, if (!condition, iconDir = FileLocationClass:getIconsDir; img = open( resources || "assert-error.png", png ); img << setSize({194,248}); NewWindow(title, <<Modal, BorderBox(top(0),bottom(30),left(20),right(20), VListBox( HListBox( SpacerBox(size(40,0)), PictureBox( img ) ), TextBox(msg) ) ) ); if (doThrow,throw()) ); ); |
Central to this discussion is the PNG image file called ‘assert-error’ that sits in my resources folder.
If I distribute this code as part of a JMP add-in, then I can include the resources folder as part of the add-in build. But I don’t want to do that. I just want a simple JSL file that other programmers can include into their projects.
My first step is to look at the img object that I am producing. So I create a utility script:
1 2 |
img = open( resources || "assert-error.png", png ); show(img); |
JMP’s log window shows the result:
1 |
img = New Image(Char To Blob( "63Yyz... waJ", "base64compressed" ), "png"); |
The entire output is long so I’ve put “…” in rather than the full text which is about 50,000 characters in length!
Structurally:
1 2 3 4 |
img = newImage( charToBlob( strImg, "base64compressed" ), "png" ); |
And this is the code that I can use to embed my image. The string representation I get from my log window output of my utility script:
1 2 3 4 5 |
strImg = "63Yyz... waJ”; // the full 50k characters here img = newImage( charToBlob( strImg, "base64compressed" ), "png" ); |
And that’s it. Problem solved.
西伯利亚金属,来自俄罗斯的力量。 https://remz.org/