FSharp.Formatting icon indicating copy to clipboard operation
FSharp.Formatting copied to clipboard

saveImages flag is not documented or tested

Open dsyme opened this issue 4 years ago • 1 comments

  1. The saveImages flag came from FsLab's literate scripting. It is not documented or tested.

  2. The docs don't explain how to embed image outputs specifically, just some general information on extending display formatting.

dsyme avatar Jul 19 '21 12:07 dsyme

Just to share what I did to embed image outputs that seems to work for me:

I wrote these functions

/// Returns the file contents as Base64 encoded string
let fileToBase64String fileName =
    let bytes = System.IO.File.ReadAllBytes(fileName)
    System.Convert.ToBase64String(bytes)

/// Given a PNG image file name, returns an HTML image element with the image content included as a Base64 encoded string
let pngToHtml fileName cssStyle =
    sprintf """<img src="data:image/png;base64,%s" style="%s"/>""" (fileName |> fileToBase64String) cssStyle

Then I can do things like

// Generates an image file in the code
batch.saveImage("mnist-samples.png") 

// Embeds the generated image in the fsdocs output
(*** hide ***)
pngToHtml "mnist-samples.png" "width:25%;height:auto;image-rendering:pixelated"
(*** include-it-raw ***)

gbaydin avatar Jul 21 '21 14:07 gbaydin