param([string]$Source, [string]$Target, [int]$X, [int]$Y, [int]$Width, [int]$Height, [int]$Zoom = 2) Add-Type -AssemblyName System.Drawing $image = [System.Drawing.Image]::FromFile((Resolve-Path -LiteralPath $Source)) try { $crop = New-Object System.Drawing.Bitmap($Width, $Height) $graphics = [System.Drawing.Graphics]::FromImage($crop) try { $graphics.DrawImage($image, (New-Object System.Drawing.Rectangle(0, 0, $Width, $Height)), $X, $Y, $Width, $Height, [System.Drawing.GraphicsUnit]::Pixel) } finally { $graphics.Dispose() } $factor = [int]$Zoom $zoomWidth = [int]$Width * $factor $zoomHeight = [int]$Height * $factor $scaled = New-Object System.Drawing.Bitmap($zoomWidth, $zoomHeight) $scaledGraphics = [System.Drawing.Graphics]::FromImage($scaled) try { $scaledGraphics.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::NearestNeighbor $scaledGraphics.DrawImage($crop, 0, 0, $zoomWidth, $zoomHeight) } finally { $scaledGraphics.Dispose() } $scaled.Save($Target, [System.Drawing.Imaging.ImageFormat]::Png) $scaled.Dispose(); $crop.Dispose() } finally { $image.Dispose() }