I try dynamically insert images in my HTML file, when I say dynamically it mean when it will be asked by a user, here 2 approce that I imagine, for both case user must before running the code put the images in a specific folder.
Via a switch parameter like: generate-html -includeImages
, if switch param is true then convert all images in MyImagefolder and insert one after one in my output.
or
Via a parameter that accept multiple value and in this case user must enter the images names like generate-html -includeImages image1.gif, image2.gif
Here the code that I use for insert one image to my HTML file:
$PSScriptRoot = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
$image = "$PSScriptRootimg.gif"
$ImageBits = [Convert]::ToBase64String((Get-Content $image -Encoding Byte))
$ImageHTML = "<img src=data:image/png;base64,$($ImageBits) alt='My Image'/>"
Then I insert my variable in my convertto-html
command.
ConvertTo-Html -Body $style -PreContent "$imageHTML" | Out-File "$PSScriptRoot
eport.html"
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…