PSWriteHTML icon indicating copy to clipboard operation
PSWriteHTML copied to clipboard

New-HTMLImage issue with SVG images

Open matt555 opened this issue 2 years ago • 1 comments

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

matt555 avatar Aug 15 '23 20:08 matt555

@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.

StartAutomating avatar Aug 18 '23 06:08 StartAutomating