Search code examples
batch-fileresizeimage-resizingmogrify

Resize images with batch file recursive directories


I'm trying to resize a bunch of images on a Windows machine, with imagemagick installed and also have git for windows.

The images need to be resized to 50% of their current size.

Inside a root directory theres directories that could contain images and others directories with images. I need to resize all the images. In my particular case I have a total of 250 folders (nested in different levels) with a total of 4110 images.

Example root folder

RootFolder
   Folder A
      ImageA.png
      SubFolder A
          ImageB.png
          ImageC.png
   Folder B
      Subfolder B
          ImageC.png

I'm trying this way, but if fails to get the correct paths.

for /r /d %%a in (*) 
do 
    find . -name "*.png" -print0 | xargs -0 mogrify -resize 50%

Error message

find . -name "\Default\*.png" -print0   | xargs -0 mogrify -resize 50
Access denied - .
File not found - -NAME
File not found - -PRINT0

Solution

  • What about this command line in a batch file to resize all PNG images in current directory and all subdirectories except hidden directories and files to 50% in width and height and overwrite input file using IrfanView?

    @for /R %%I in (*.png) do @"%ProgramFiles(x86)%\IrfanView\i_view32.exe" "%%I" /resize=(50p,50p) /convert="%%I"
    

    The same command line for execution directly from within a command prompt window without usage of a batch file:

    for /R %I in (*.png) do @"%ProgramFiles(x86)%\IrfanView\i_view32.exe" "%I" /resize=(50p,50p) /convert="%I"
    

    Open a command prompt window, run for /? and read the output help.

    For the options of IrfanView (freeware for private usage) read the text file i_options.txt in program files folder of installed IrfanView.

    I don't have ImageMagick installed and you have not posted the ImageMagick command line to resize a PNG image which is the reason why I posted a command line solution using IrfanView.

    One more note: There is no need for a batch file for this task. Open IrfanView, click in menu File on menu item Batch Conversion/Rename and use this dialog to select with a few clicks all *.png image files in your directory tree, set the options for resize and PNG optimization and execute batch conversion.