简体   繁体   中英

How would I use ImageMagick in a .bat file (Windows) to resize all images in all sub-directories?

I have tens of thousands of images on a Windows server. Files are all sizes from 100x100 up to 6000x6000 pixels. Files are jpg, gif, and png. Files are in many nested folders.

I have Imagemagick installed on the server. I am looking for help to write an ImageMagick script that could run from a bat file (the top-most directory would be passed in as an argument as well as the maximum pixel size).

The script would process every image file in the top-most directory and all sub-directories recursively. It would resize the image only if the width or height was larger than the maximum pixel size (if the maximum pixel size parameter was 1200 it would resize an image that is 4000x2000, but not an image that is 100x500). It would resize the width or height (whichever is larger) to the maximum pixel size and change the size of the other dimension to be proportional (ie, it would not skew or distort the image when resizing it).

Is it possible to write an ImageMagick script that does all of that?

So, the information in the links from fmw42 was enough to cobble together an answer.

FOR /R %f IN (*.jpg) DO mogrify -verbose -resize "1200x1200>" "%f"

This will recursively affect every .jpg file in and under the folder this is run from ( FOR /R %f IN (*.jpg) DO ).

Each file will be shrunk to fit within a 1200x1200 box, maintaining the images aspect ratio, if the image in question is larger than 1200px in either direction.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM