auto_level_gray_paper.cmd 940 B

12345678910111213141516171819202122232425262728293031323334
  1. @echo off
  2. chcp 65001
  3. setlocal enableextensions enabledelayedexpansion
  4. set "SRCPATH=%~1"
  5. if not defined SRCPATH set "SRCPATH=%~dp0"
  6. set "DESTPATH=%~2"
  7. if not defined DESTPATH set "DESTPATH=%~dp0/out"
  8. if not exist "%DESTPATH%" mkdir "%DESTPATH%"
  9. set "FILEMASKS=%~3"
  10. if not defined FILEMASKS set "FILEMASKS=\.*.png$"
  11. set "TMPPATH=%Temp%"
  12. if not exist "%SRCPATH%\*" call PRINT_USAGE
  13. if not exist "%DESTPATH%\*" ( md "%DESTPATH%" || exit /b )
  14. if not exist "%TMPPATH%\*" ( md "%TMPPATH%" || exit /b )
  15. for /f "usebackq tokens=* delims=" %%I in ( `dir /b /a:-d "%SRCPATH%\*" 2^>NUL ^| findstr /i "%FILEMASKS%" 2^>NUL` ) do (
  16. set FN=%%~nxI
  17. @echo.Processing file !FN:\=\\!
  18. gm convert -colorspace gray -level "65%%,4,100%%" "!SRCPATH!/!FN!" "%DESTPATH%\!FN:\=\\!"
  19. )
  20. echo.Ready.
  21. echo.&pause&goto:eof
  22. :PRINT_USAGE
  23. echo:
  24. echo USAGE:
  25. echo %~n0 ^<source^> ^<destination^> [filemask]
  26. exit /b !ERRORLEVEL!