This guide covers batch-resizing images to a maximum width, converting to WebP or JPEG, and handling common edge cases like mixed orientations and already-small files. Unlike the step-by-step pipeline tutorial, this guide focuses on production batch concerns: preserving subdirectory layout, enforcing JPEG file-size ceilings, and resize modes (width-only, height-only, exact crop, letterbox padding) beyond a single “fit in a box” recipe.Documentation Index
Fetch the complete documentation index at: https://hackmamba-3f164318.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Resize and convert a single image
Constrain an image to a maximum width of 1200 pixels and output as WebP:1200x> geometry means “width at most 1200, never upscale”; see Geometry syntax reference for the full modifier table. The -quality number is documented under -quality; examples in this guide use 85 as a shared web default so commands stay consistent with the rest of the site.
Batch a flat folder with a loop
An explicitfor loop runs one magick command per file. You get readable logs, per-file error handling, and room to add guards or logging, which is why many teams prefer loops over mogrify in production scripts.
Resize every JPEG in photos/ and write matching WebP files into web/:
WEBP in the format column and dimensions at or below your resize rule.
Same loop on Windows PowerShell:
Batch a flat folder with mogrify
You can express the same flat-folder job as a singlemogrify invocation when you already trust every file matched by the glob and you have set -path so originals are not overwritten.
After
mogrify, run magick identify web/*.webp to confirm each output exists and shows the WEBP format and expected geometry.Batch-convert with subdirectories
mogrify does not recurse into subdirectories or preserve folder structure. Use find with a loop:
- Linux / macOS
- Windows (PowerShell)
web/: for example, photos/shoes/boot1.jpg becomes web/shoes/boot1.webp, preserving the shoes/ segment between photos/ and the filename.
When one file fails mid-batch
magick mogrify applies the same operation to every path in the glob. If one input is corrupt or unreadable, mogrify can exit and leave the rest untouched (behavior depends on version and delegates; always read the terminal message).
When you need per-file control, a loop can log failures and continue with the remaining paths:
|| true after magick so a failed file does not abort the shell script. Use this only when silently skipping failures is acceptable:
$? after the loop if you wrap this in automation.
Fix rotated phone photos
Add-auto-orient (an operator that runs at its position in the command) before any resize operation to correct rotation flags from phone cameras. Pair it with -quality (a setting that applies to the next lossy write) as you already do elsewhere in this guide:
Enforce a file size ceiling (JPEG)
For JPEG output,-define jpeg:extent caps the file size. ImageMagick adjusts quality downward as needed:
-define jpeg:extent forces ImageMagick to lower effective quality until the file is at or under the limit (exact behavior depends on content and JPEG encoder settings). Confirm with wc -c or your file manager after running the command on your assets.
jpeg:extent is specific to JPEG output. WebP has no equivalent built-in ceiling. For WebP, control file size through -quality.Resize to different constraints
Constrain by width only
Constrain by height only
Exact dimensions with center crop
Use this when the destination must be an exact pixel size (for example a 1200×800 hero slot) and cropping edges is acceptable. Tall or wide sources are scaled until the box is filled, then overflow is cut off. That is ideal when the layout fixes width and height and you do not want letterboxing. Fill the target dimensions and crop overflow from the center:^ differs from other resize modifiers.
Fit within a box with padding
Use this when the platform needs a square (or fixed) canvas but must not crop the subject (for example marketplace tiles that show the full product with letterboxing instead of cutting off limbs or labels). The image is scaled to fit inside the box, then the canvas is padded to the exact size with a background color. Resize to fit inside 800x800, then pad the remaining space with a background color:Next steps
- Walk through a full resize → strip → watermark → WebP flow in the image processing pipeline tutorial.
- Look up modifiers such as
>,^, and!in the Geometry syntax reference. - Read flag-level details in the common options reference.
- If commands fail or output looks wrong, use Troubleshooting.