ImageDataUriConverter
A Powershell module for data URI to/from image file conversion, and data URI resizing.
Available in the Powershell Gallery
Description
Convert an image file to a base64 data URI, create an image file from a base64 data URI, or resize a data URI as a new data URI.
Optionally resize the image prior to data URI conversion (original file retained, resizing is done in memory).
Installation (from the Powershell Gallery)
Install-Module ImageDataUriConverter
Import-Module ImageDataUriConverter
Included cmdlets
Invoke-ImageToDataUri
Invoke-DataUriToImage
Invoke-DataUriResize
Examples
Convert an image file to a data uri and copy to clipboard
Invoke-ImageToDataUri -File 'C:\Temp\an.image.png' -CopyToClipboard
Convert an image file to a data uri using pipeline and resize to 30px x 30px
'C:\Temp\an.image.png' | Invoke-ImageToDataUri -Width 30 -Height 30
Convert an image file to a data uri within an html img tag
Invoke-ImageToDataUri -File 'C:\Temp\an.image.png' -AsHtmlImgTag
Create an image file from a base64 data uri
Invoke-DataUriToImage -DataUri 'data:image/png;base64,iVBORw0K...'
Create an image file from a base64 data uri and specify the image file to be created
Invoke-DataUriToImage -DataUri 'data:image/png;base64,iVBORw0K...' -OutFile 'C:\Temp\an.image.png'
Resize a data uri to 30px x 30px and copy to clipboard
Invoke-DataUriResize -DataUri 'data:image/png;base64,iVBORw0K...' -Width 30 -Height 30 -CopyToClipboard
Building the module and importing locally
Build the .NET core solution
dotnet build [Github clone/download directory]\ps-image-data-uri-converter\src\PsImageDataUriConverter.csproj
Copy the built files to your Powershell modules directory
Remove any existing installation in this directory, create a new module directory and copy all the built files.
Remove-Item "C:\Users\[User]\Documents\PowerShell\Modules\ImageDataUriConverter" -Recurse -Force -ErrorAction SilentlyContinue
New-Item -Path 'C:\Users\[User]\Documents\PowerShell\Modules\ImageDataUriConverter' -ItemType Directory
Get-ChildItem -Path "[Github clone/download directory]\ps-image-data-uri-converter\src\PsImageDataUriConverterCmdlet\bin\Debug\net6.0\" | Copy-Item -Destination "C:\Users\[User]\Documents\PowerShell\Modules\ImageDataUriConverter" -Recurse
Contribute
Please raise an issue if you find a bug or want to request a new feature, or create a pull request to contribute.