Created
March 18, 2023 14:37
-
-
Save catb0x/fc70b72306305e02201be8705fe78488 to your computer and use it in GitHub Desktop.
Resize images without any external programs or modules. (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
function Img-Resize { | |
param( | |
[string]$Path, | |
[string]$FileType, | |
[int]$Width, | |
[int]$Height | |
) | |
$Image = [System.Drawing.Image]::FromFile("$Path") | |
$NewImage = New-Object System.Drawing.Bitmap $Width, $Height | |
$Graphics = [System.Drawing.Graphics]::FromImage($NewImage) | |
$Graphics.DrawImage($Image, 0, 0, $Width, $Height) | |
$Image.Dispose() | |
$NewImage.Save($Path, [System.Drawing.Imaging.ImageFormat]::$FileType) | |
$NewImage.Dispose(); $Graphics.Dispose() | |
} | |
# Example: Img-Resize C:\Users\Admin\Downloads\cat.jpg Jpeg 128 128 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment