This is an example of powershell script function that changes image format and size.
I've just updated the code from internet and using this on my powershell project.
$image is the file path of image file.
[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
function Convert-Image{
param($image,$toFormat,$saveTo,$smalldim,$bigdim)
$baseName = [System.IO.Path]::GetFileNameWithoutExtension($image)
$img = [System.Drawing.Image]::FromFile($image)
"$image"
if ($img.Width -gt $img.Height) {
$width = $bigdim
$height = $smalldim
} else {
$width = $smalldim
$height = $bigdim
}
$ResizedImage = New-Object System.Drawing.Bitmap @($width, $height)
$graphics = [System.Drawing.Graphics]::FromImage($ResizedImage)
$graphics.DrawImage($img, 0, 0, $Width, $Height)
$graphics.Dispose()
$ResizedImage.save("$saveTo\$baseName.$toFormat",$toFormat)
}
I'm new to powershell, can you explain this script a little more? So wherever it says $image, then I should put the full path to the picture?
ReplyDeleteYes, as you aware, $image is a full path to the picture.
Delete