Last active
May 5, 2024 20:09
-
-
Save RyKilleen/6086c6a7b2ae06a3ea01396d79d637c7 to your computer and use it in GitHub Desktop.
ImageMagick / Powershell: limit file size in parallel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$directory = "C:\full-path\to-photos-directory" | |
# Only .jpg files larger than 10mb | |
$files = Get-ChildItem -Path $directory -Filter *.jpg | Where-Object Length -gt 10mb | |
# Use ForEach-Object with the -Parallel parameter | |
$files | ForEach-Object -Parallel { | |
# Define the new filename with '_edited' suffix | |
$newFileName = [IO.Path]::Combine($_.DirectoryName, ($_.BaseName + "_edited" + $_.Extension)) | |
# Execute ImageMagick command to resize the file | |
& magick convert $_.FullName -define jpeg:extent=10000kb $newFileName | |
} -ThrottleLimit 5 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment