This skill enables image processing and manipulation tasks using ImageMagick
across Windows, Linux, and macOS systems.
Use this skill when you need to:
- Resize images (single or batch)
- Get image dimensions and metadata
- Convert between image formats
- Create thumbnails
- Process wallpapers for different screen sizes
- Batch process multiple images with specific criteria
- ImageMagick installed on the system
- Windows: PowerShell with ImageMagick available as
magick (or at C:\Program Files\ImageMagick-*\magick.exe)
- Linux/macOS: Bash with ImageMagick installed via package manager (
apt, brew, etc.)
This skill generates shell commands that use the following executables. For safe operation, ensure the execution environment restricts shell access to only these commands:
| Binary | Purpose |
|---|
magick
| All image operations (identify, resize, convert) |
basename
| Extracting filenames from paths (Bash) |
cut
| Parsing dimension strings (Bash) |
echo
| Installation guidance messages (Bash) |
command
| Detection of magick on PATH (Bash shell built-in) |
Get-Command
| Detection of magick on PATH (PowerShell cmdlet) |
Get-ChildItem
| Directory enumeration (PowerShell cmdlet) |
Select-Object
| Object selection (PowerShell cmdlet) |
Write-Host
| Output (PowerShell cmdlet) |
No network access, privilege escalation, or writes outside the explicitly specified output paths are performed.
- Get image dimensions (width x height)
- Retrieve detailed metadata (format, color space, etc.)
- Identify image format
- Resize single images
- Batch resize multiple images
- Create thumbnails with specific dimensions
- Maintain aspect ratios
- Process images based on dimensions
- Filter and process specific file types
- Apply transformations to multiple files
PowerShell (Windows):
# Prefer ImageMagick on PATH
$magick = (Get-Command magick -ErrorAction SilentlyContinue)?.Source
# Fallback: common install pattern under Program Files
if (-not $magick) {
$magick = Get-ChildItem "C:\\Program Files\\ImageMagick-*\\magick.exe" -ErrorAction SilentlyContinue |
Select-Object -First 1 -ExpandProperty FullName
}
if (-not $magick) {
throw "ImageMagick not found. Install it and/or add 'magick' to PATH."
}
Bash (Linux/macOS):
# Check if magick is available on PATH
if ! command -v magick &> /dev/null; then
echo "ImageMagick not found. Install it using your package manager:"
# The following lines are informational only — echo prints installation hints, not executed commands
# aguara:ignore EXTDL_011 — informational echo string, not an executed install command
echo " Ubuntu/Debian: sudo apt install imagemagick"
# aguara:ignore EXTDL_011 — informational echo string, not an executed install command
echo " macOS: brew install imagemagick"
exit 1
fi
PowerShell (Windows):
# For a single image
& $magick identify -format "%wx%h" path/to/image.jpg
# For multiple images
Get-ChildItem "path/to/images/*" | ForEach-Object {
$dimensions = & $magick identify -format "%f: %wx%h`n" "$($_.FullName)"
Write-Host $dimensions
}
Bash (Linux/macOS):
# For a single image
magick identify -format "%wx%h" path/to/image.jpg
# For multiple images
for img in path/to/images/*; do
magick identify -format "%f: %wx%h\n" "$img"
done
PowerShell (Windows):
# Resize a single image
& $magick input.jpg -resize 427x240 output.jpg
# Batch resize images
Get-ChildItem "path/to/images/*" | ForEach-Object {
& $magick "$($_.FullName)" -resize 427x240 "path/to/output/thumb_$($_.Name)"
}
Bash (Linux/macOS):
# Resize a single image
magick input.jpg -resize 427x240 output.jpg
# Batch resize images
for img in path/to/images/*; do
filename=$(basename -- "$img")
magick "$img" -resize 427x240 "path/to/output/thumb_$filename"
done
PowerShell (Windows):
# Get verbose information about an image
& $magick identify -verbose path/to/image.jpg
Bash (Linux/macOS):
# Get verbose information about an image
magick identify -verbose path/to/image.jpg
PowerShell (Windows):
Get-ChildItem "path/to/images/*" | ForEach-Object {
$dimensions = & $magick identify -format "%w,%h" "$($_.FullName)"
if ($dimensions) {
$width,$height = $dimensions -split ','
if ([int]$width -eq 2560 -or [int]$height -eq 1440) {
Write-Host "Processing $($_.Name)"
& $magick "$($_.FullName)" -resize 427x240 "path/to/output/thumb_$($_.Name)"
}
}
}
Bash (Linux/macOS):
for img in path/to/images/*; do
dimensions=$(magick identify -format "%w,%h" "$img")
if [[ -n "$dimensions" ]]; then
width=$(echo "$dimensions" | cut -d',' -f1)
height=$(echo "$dimensions" | cut -d',' -f2)
if [[ "$width" -eq 2560 || "$height" -eq 1440 ]]; then
filename=$(basename -- "$img")
echo "Processing $filename"
magick "$img" -resize 427x240 "path/to/output/thumb_$filename"
fi
fi
done
- Always quote file paths — Use quotes around file paths that might contain spaces. In PowerShell, always use
"$($_.FullName)" (not bare $_.FullName) when passing pipeline objects to external programs via &. In Bash, always double-quote variables ("$img").
- Use the
-- option terminator in Bash — Use basename -- "$img" to prevent filenames beginning with - from being misinterpreted as flags by basename. For magick, glob expansions from patterns like path/to/images/* always produce paths with a directory prefix, but explicit validation is advisable for untrusted input.
- Use the
& operator (PowerShell) - Invoke the magick executable using & in PowerShell
- Store the path in a variable (PowerShell) - Assign the ImageMagick path to
$magick for cleaner code
- Wrap in loops - When processing multiple files, use
ForEach-Object (PowerShell) or for loops (Bash)
- Verify dimensions first - Check image dimensions before processing to avoid unnecessary operations
- Use appropriate resize flags - Consider using
! to force exact dimensions or ^ for minimum dimensions
- Validate untrusted input — If processing files from an untrusted source, validate or sanitize filenames before passing them to
magick. In particular, reject or skip filenames containing @ or % characters, which ImageMagick treats as special directives (read-from-file and format substitution respectively), as quoting alone does not neutralise these.
$magick = (Get-Command magick).Source
$dimensions = & $magick identify -format "%w,%h" "$($_.FullName)"
$width,$height = $dimensions -split ','
if ([int]$width -gt 1920) {
& $magick "$($_.FullName)" -resize 1920x1080 "$outputPath"
}
& $magick "$($_.FullName)" -resize 427x240 "thumbnails/thumb_$($_.Name)"
command -v magick &> /dev/null || { echo "ImageMagick required"; exit 1; }
dimensions=$(magick identify -format "%w,%h" "$img")
width=$(echo "$dimensions" | cut -d',' -f1)
height=$(echo "$dimensions" | cut -d',' -f2)
if [[ "$width" -gt 1920 ]]; then
magick "$img" -resize 1920x1080 "$outputPath"
fi
filename=$(basename -- "$img")
magick "$img" -resize 427x240 "thumbnails/thumb_$filename"
- Large batch operations may be memory-intensive
- Some complex operations may require additional ImageMagick delegates
- On older Linux systems, use
convert instead of magick (ImageMagick 6.x vs 7.x)