Last active
March 30, 2024 16:03
-
-
Save pferreirafabricio/6120ee40c2455477411454be7d1359f4 to your computer and use it in GitHub Desktop.
Script to loop through a folder with images and convert all of them to a Base64 string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
Usage on Linux: | |
pwsh ./convertImagesToBase64.ps1 /home/user/folder/images | |
Usage on Windows: | |
./convertImagesToBase64.ps1 C:/Path/To/Imagens | |
#> | |
$folderPath = $args[0] | |
Write-Output "Starting the conversion" | |
$allImages = Get-ChildItem $folderPath -Filter *.png | |
foreach ($image in $allImages) { | |
$fileName = $image.Name | |
Write-Output "Converting the image: $fileName" | |
# OBS: For more information on how convert a file to base64 take a look at this gist: [png-to-base64.ps1](https://gist.github.com/pferreirafabricio/97c1c68057e406ff0f98840659973f0d) | |
[String]$base64 = [convert]::ToBase64String((Get-Content $image.FullName -Raw -AsByteStream)) | |
Write-Output $base64 | |
} | |
Write-Output "All images were converted" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OBS: Remember to download PowerShell on Linux: Installing PowerShell on Linux