Last active
August 13, 2022 13:42
-
-
Save kneeprayer/cf318264636cf1e0c904baa5f4e650cb to your computer and use it in GitHub Desktop.
Invert Color Of An Image Using Powershell
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 : .\Invert-Image.ps1 .\test*.png | |
# | |
[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | Out-Null | |
Get-ChildItem $args[0] | ForEach-Object { | |
$image = New-Object System.Drawing.Bitmap($_.fullname) | |
for ($y = 0; $y -lt $image.Height; $y++) { | |
for ($x = 0; $x -lt $image.Width; $x++) { | |
$pixelColor = $image.GetPixel($x, $y) | |
$varR = 255 - $pixelColor.R | |
$varG = 255 - $pixelColor.G | |
$varB = 255 - $pixelColor.B | |
$image.SetPixel($x, $y, [System.Drawing.Color]::FromArgb($varR, $varG, $varB)) | |
} | |
} | |
$image.MakeTransparent($image.GetPixel(10, 10)) | |
$newFileName = $_.FullName -replace ".png", "-2.png" | |
$image.Save($newFileName) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment