Home > Back-end >  Batch command for ImageMagick to crop width of all files in a directory
Batch command for ImageMagick to crop width of all files in a directory

Time:05-08

I have hundreds of images in a folder of size 1920x~100,000. I need to cut out the middle 900p of every file leaving the height unaffected. how do I pass each file to this command? magick convert image.jpg -crop 900x 510 0 result.jpg

CodePudding user response:

@echo off
setlocal
md "destinationdirectory" 2>nul
pushd "sourcedirectory"
for %%e in (*.jpg) do magick convert "%%e" -crop 900x 510 0 "destinationdirectory\%%e"
popd

simply substitute your directory names for sourcedirectory and destinationdirectory - and they can't be the same directory.

CodePudding user response:

Two options:

  1. use mogrify instead of convert to replace the image with the result
  2. Let IM deduce the output file from the input fil:
convert *.jpg -crop 900x 510 0 -set filename:base "%[basename]" "%[filename:base]-cropped.jpg"

(or use a similar idiom to target a different directory)

  • Related