cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Craige_Hales
Super User
HTML with Embedded Images

This is NOT for saving interactive HTML. SaveInteractiveHTML already does this. You should probably use it instead.

 

When JMP saves HTML with graphics, it creates a directory named gfx to hold the images. The gfx directory will hold images for all the HTML files that are saved in the same parent directory. If you send the HTML to someone, they only need the files for that HTML, and they need to put the gfx directory and the HTML  in the same location. It works pretty well if you have a server where you can put them, but not so good if you email them.

This example JSL will embed the images into the HTML using a Data URL (formerly known as a Data URI). The gfx is not needed after conversion because the pictures are moved into the HTML.

@ihnleung 

// https://community.jmp.com/t5/Discussions/Distribution-plots-not-showing-in-Journal-saved-as-html/m-p/475041#M71971
// asked about emailing html reports. This code is an example of how the external
// images in the gfx folder can be converted into embedded URI data.
// most browsers should support this; it makes the html bigger, of course, but
// doesn't need the images in a shared directory.
workdir = "$temp/deleteme/";// careful! this dir is deleted ...
Delete Directory( workdir );// BANG!
Create Directory( workdir );// create empty dir
//
// make a journal with some reports and save it as html with external images in the gfx dir
//
dt = Open( "$sample_data/big class.jmp" );
bv = dt << Bivariate( Y( :weight ), X( :height ), Fit Line );
bv << journal;
bv << closewindow;
ow = dt << Oneway( Y( :height ), X( :sex ), Means( 1 ), Mean Diamonds( 1 ) );
ow << journal;
ow << closewindow;
Close( dt, nosave );
Current Journal() << savehtml( workdir || "x.html" );
Current Journal() << closewindow;
//
// load the html just saved above and embed the images in the gfx directory
//
html = Load Text File( workdir || "x.html" );// get the journal's html
snips = {}; // collect the snipped up html here
rc = Pat Match(// loop through the html, snipping it up into 'not file' and 'file' sections
    html, // the html that needs the files converted into URI (inline pictures)
    Pat Repeat(
        Pat Arb() >> txt // txt holds a snip of html that is not a picture file name
        + // text before a filename, above, is followed by a filename (or the end), below
        (
            ("<img src=\!"" + Pat Break( "\!"" ) >> file + "\!"") // file holds a picture name
        | // alternative at the end, there is no filename
            Pat R Pos( 0 ) >> file // made it to the end of the text, file is "" in this case
        ) + //
        Pat Test( //
            Insert Into( snips, txt ); // first snip
            If( file != "", // second snip, except not at the end
                Insert Into( // replace the snipped part with embedded data
                    snips, // https://stackoverflow.com/questions/6826390/how-to-convert-image-to-data-uri-for-html-with-c
                    "<img src=\!"data&colon;image/" || Right( file, 3 )/*png or jpg*/ || ";base64," //
                    || Encode64 Blob( Load Text File( workdir || file, blob() ) ) //
                    || "\!"" //
                ) //
            ); //
            1; // pattest succeeds
        ) + //
        Pat Fence() // optimize backtracking behavior by fencing off work completed
    ) //
);
If( rc == 1,
    html = Concat Items( snips );// put the snips together 
    filename = savetextfile(workdir || "uri.html", html); // save the embedded version
    open(filename); // quick test
, //
    Throw( "failed" ); // bummer. the pattern match has failed.
);

Looks like the JSL might get mangled( & colon ; instead of : ) because of the html inside of html...the attached file might work better.

 

Last Modified: Apr 30, 2022 9:48 PM
Comments