Found some useful code to assist with embedding images as Base64. Outputs element style tag as well as image element:
function retBase64Image($path){
$newImg = [convert]::ToBase64String((get-content $path -encoding byte))
$ext = gci $path | select @{Name="Ext";Expression={$_.Extension.substring(1)}} | select -ExpandProperty Ext
Write-Host "style='background:url(data:image/$ext;base64,$newImg) right bottom no-repeat'"
Write-Host "<img src='data:image/$ext;base64,$newImg' />"
}
retBase64Image -path "C:\MyImages\Image1.gif"
No comments:
Post a Comment