Skip to main content

One post tagged with "Image Magick"

View All Tags

ImageMagick Resize

· One min read

Resize Images with Image Magick

A small script to resize your images with ImageMagick and Powershell using multi threading. Easiest to install Imae Magick is using

Install ImageMagick with winget
winget install imagemagick

Make sure that the Image Magick folder is in your path.

The Powershell script has two parameters:

  • resizePercentage: How large should the resulting pictures be compared to the original?
  • suffix: This will be added to the image name

The script is using '*.jpg' as a filter - adjust if needed:

Resize images with ImageMagick
# Set variables
$resizePercentage = 50
$suffix = "_50"

$scriptBlock = {
param($fileName, $newFileName, $resizePercentage)
magick $fileName -resize $resizePercentage% $newFileName
}

# Get all .jpg files and start jobs
$jobs = @()
Get-ChildItem -Path . -Filter *.jpg | ForEach-Object {
$newFileName = $_.BaseName + $suffix + ".jpg"
$job = Start-Job -ScriptBlock $scriptBlock -ArgumentList $_.Name, $newFileName, $resizePercentage
$jobs += $job
Write-Host "Started conversion job for $($_.Name)" -ForegroundColor Cyan
}

# Wait for all jobs to complete
$jobs | Wait-Job