すごくメモ帳

すごくほぼメモ帳ぐらいなブログ

PowerShell で画像縮小

256x256 の画像を 128x128 にするスクリプト

環境構築不要。メモ帳に書いて PowerShell で実行するだけ。

using namespace System.Drawing

function resize($src, $dst, $width, $height){
    $img = [Bitmap]::new($src)
    $rImg = [Bitmap]::new($width, $height)
    $g = [Graphics]::FromImage($rImg)
    $g.DrawImage($img, 0, 0, $width, $height)
    $rImg.save($dst)
    $img.Dispose()
    $rImg.Dispose()
    $g.Dispose()
}

$file = (pwd).path + "\Lenna.bmp"
$dst = (pwd).path + "\Lenna_128.bmp"

resize $file $dst 128 128