ImageMagick batch convert all PNGs in subdirectories to JPEGs

Try using the following at the cmd prompt:

mogrify -format jpg *.png

I wasted hours trying use the ImageMagick convert command in a batch file, but couldn't get it to work


For novice:

Download ImageMagick from below link:

https://www.imagemagick.org/script/download.php

then just copy and paste below command in cmd:

for /r /d %a in (*) do "C:\Program Files\ImageMagick-7.0.6-Q16\magick.exe" mogrify -format png "%~a\*.jpg"

The above command is working fine for me which converts all files from JPGs to PNGs, present in the current directory.

And then if you want to remove all the residual JPGs, just hit the below command:

for /r %i in (*.jpg) do del "%i"

You could always perform a for-loop:

cd D:\images
for /r /d %%a in (*) do mogrify -format jpg "%%~a\*.png"

Which will run the command for every sub-folder such that it is:

mogrify -format jpg "D:\images\name of subfolder\*.png"

Which appears to meet your requirements.

To use this code in command prompt replace %%a with %a

Edit

To use this code as it is you would need to put it in a batch-file. A very simple procedure for this is to:

  1. Open Notepad or any other text editor
  2. Copy and paste the code into it
  3. Save as and when naming it call it "something.bat"
  4. Before clicking save make sure you set the file-type to All Files (*.*) in the drop-down menu below the name.
  5. Whenever you want to perform the operation simply find "something.bat" or whatever you named it and double click to run.

That way you don't have to open cmd every time you want to perform the action.