Skip to content

Instantly share code, notes, and snippets.

@catb0x
Created March 18, 2023 14:37
Show Gist options
  • Save catb0x/fc70b72306305e02201be8705fe78488 to your computer and use it in GitHub Desktop.
Save catb0x/fc70b72306305e02201be8705fe78488 to your computer and use it in GitHub Desktop.
Resize images without any external programs or modules. (Powershell)
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