EvotecIT / PSWriteHTML

PSWriteHTML is PowerShell Module to generate beautiful HTML reports, pages, emails without any knowledge of HTML, CSS or JavaScript. To get started basics PowerShell knowledge is required.
MIT License
826 stars 106 forks source link

New-HTMLImage issue with SVG images #398

Closed matt555 closed 3 months ago

matt555 commented 1 year ago

When supplying New-HTMLImage -Inline with an SVG image (file or URI) it creates an invalid mime type (at least in modern browsers, unsure of the history there).

In short: svg should instead be svg+xml

Current html output:

<img src="data:image/svg;base64, blahblah123 ></img>

Working html:

<img src="data:image/svg+xml;base64, blahblah123 ></img>

Fix: Seems like an easy fix to add the below elseif to https://github.com/EvotecIT/PSWriteHTML/blob/master/Private/Convert-ImageToBinary.ps1#L9-L9

    if ($ImageFile.Extension -eq '.jpg') {
        $FileType = 'jpeg'
    } elseif ($ImageFile.Extension -eq '.svg') {
        $FileType = 'svg+xml'
    } else {
        $FileType = $ImageFile.Extension.Replace('.', '')
    }

Matt

StartAutomating commented 1 year ago

@EvotecIT this one looks pretty simple. There's a light curveball here in that SVG files can also be inline as elements within the page.

This has some trade-offs: it spaces a little differently than within an tag if it's inline (not as great), and it can include JavaScript and align to CSS classes defined elsewhere in the HTML if it's actually "inline".

I think a [switch] might be required to make this ideal.

Feel free to assign it to me and I'll try to run with it.