You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows环境下借助ImageMagick批量递归调整图片至原尺寸50%

Batch Resize Images to 50% Across Nested Folders (Windows with ImageMagick + Git Bash)

Got it, let's get this sorted for you. Since you already have ImageMagick and Git for Windows installed, we can combine Git Bash's shell tools with ImageMagick's powerful resizing commands to handle all 4110 images across those 250 nested folders. Here are two reliable methods:

Method 1: Use find Command (Most Robust)

This method will recursively scan every subfolder and target all common image formats. It’s great for large-scale batches because it handles nested directories seamlessly.

  1. Open Git Bash and navigate to your root folder (replace the path with your actual root directory):

    cd /c/Path/To/Your/Root/Folder
    
  2. Run the command below. Note: Use magick convert for newer ImageMagick versions (v7+); if you have an older version, drop the magick prefix and just use convert:

    # For ImageMagick v7+
    find . -type f \( -iname "*.jpg" -o -iname "*.png" -o -iname "*.gif" -o -iname "*.bmp" -o -iname "*.jpeg" \) -exec magick convert {} -resize 50% {} \;
    
    # For older ImageMagick versions
    find . -type f \( -iname "*.jpg" -o -iname "*.png" -o -iname "*.gif" -o -iname "*.bmp" -o -iname "*.jpeg" \) -exec convert {} -resize 50% {} \;
    

Breakdown of the command:

  • find .: Starts searching from the current directory (your root folder)
  • -type f: Targets only files (ignores folders)
  • \( -iname "*.jpg" -o ... \): Matches all common image formats, case-insensitive (so .JPG and .jpg both get picked up)
  • -exec ... \;: Runs the ImageMagick command on each matched file
  • -resize 50%: Scales the image to 50% of its original dimensions
  • {}: Represents the current file being processed (the first {} is the input, the second is the output—this overwrites the original file)

Method 2: Use Recursive for Loop (Git Bash Specific)

If you prefer a more readable loop structure, this works well in Git Bash:

  1. Open Git Bash and navigate to your root folder as before.
  2. Run these commands:
    # Enable recursive globbing (lets **/ match all nested folders)
    shopt -s globstar
    
    # Loop through all image files
    for img in **/*.{jpg,jpeg,png,gif,bmp,JPG,JPEG,PNG,GIF,BMP}; do
        # Only process if the file actually exists (avoids empty matches)
        if [ -f "$img" ]; then
            magick convert "$img" -resize 50% "$img"
            # For older ImageMagick: convert "$img" -resize 50% "$img"
        fi
    done
    

Critical Precaution

Before running the full batch, always test with a small subset first to avoid accidental data loss:

  • Replace the resizing part with a print command to verify which files will be processed. For example, in the find command, change -exec ... \; to -print:
    find . -type f \( -iname "*.jpg" -o -iname "*.png" \) -print
    
  • If you don’t want to overwrite original images, you can modify the command to save resized copies to a new directory structure. Let me know if you need help with that!

Troubleshooting

  • If ImageMagick commands aren’t recognized: Check if the ImageMagick installation folder is in your system PATH. You can also use the full path to the executable, e.g., "C:\Program Files\ImageMagick-7.1.1-Q16-HDRI\magick.exe" instead of just magick.

内容的提问来源于stack exchange,提问作者hsantos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 08:23:41