Hi,
this script could be placed somewhere (BatchResize.cmd).
Some parameters may be modified:
The searched file type is JPEG by default:
Since JPEG files can be saved with a special quality parameter this could also be changed:
Change all files bigger than 1000 pixel width and set the new long side to this value:
Be careful, this script is destructive and will overwrite pictures (take file xyz.jpg, resize it and save it back as xyz.jpg)!
Have fun
Nils
this script could be placed somewhere (BatchResize.cmd).
Code:
@echo off rem ******************* rem * BatchResize.cmd * rem ******************* rem Drag and drop a folder or folder structure to this script and IrfanView will rem resize all pictures of the given file type to the given pixel size. Smaller rem pictures will not be touched. rem Also the jpeg quality could be set. cls setlocal rem Check parameter if "%~1"=="" goto noparam rem Path to Irfan view if /i "%PROCESSOR_ARCHITECTURE%" equ "AMD64" ( rem Path to IrfanView on x64 Windows set iview="%ProgramFiles(x86)%\IrfanView\i_view32.exe" ) else ( rem Path to IrfanView on x86 Windows set iview="%ProgramFiles%\IrfanView\i_view32.exe" ) if not exist %iview% goto noIview rem File type set filetype=*.jpg rem Width set width=1000 rem JPEG quality set quality=75 rem temporaery file set tmpfile="%temp%\imageinfo.txt" echo Converting... for /r "%~1" %%a in (%filetype%) do call :Resize "%%a" echo. echo Finished converting. rem After finishing go to the end goto end :noparam echo No path given! goto end rem IrfanView could not be found. :noiview echo IrfanView not found in the given path: echo %iview% goto end :resize echo Checking file "%~1" start /wait "IrfanView" %iview% %1 /info=%tmpfile% set imagewidth=0 for /f "tokens=4 delims= " %%b in ('type %tmpfile% ^| find /i "image dimensions"') do set /a imagewidth=%%b if "%imagewidth%" gtr "%width%" ( echo Resizing file "%~1" start /wait "IView" %iview% "%~1" /resize_long=%width% /aspectratio /resample /jpgq=%quality% /convert="%~1" ) goto :eof rem End of the script :end if exist %tmpfile% del %tmpfile% pause endlocal
The searched file type is JPEG by default:
Code:
set filetype=*.jpg
Code:
set quality=75
Code:
set width=1000
Have fun
Nils
Comment