- @echo off&cd /d %~dp0&title 批量修改图片尺寸
- setlocal enabledelayedexpansion
-
- if not exist "C:\Windows\System32\nconvert.exe" (
- echo 没有nconvert,请前往下面地址下载,放入C:\Windows\System32
- echo,http://bcn.bathome.net/s/tool/index.html?key=nconvert
- pause&exit /b
- )
-
- set /p "str=请输入高或宽最大像素:"
- for /f "delims=" %%a in ('dir /ad /b /s *') do (
- pushd "%%a"&echo.&echo 进入 "%%a" 文件夹查找图片. . .
- for /f "delims=" %%b in ('dir /a-d /b "*.jpg" "*.png"') do (
- for /f "tokens=1* delims=:" %%i in ('nconvert.exe -info "%%b"^|findstr /i /l /c:"Width"') do set W=%%j&set W=!W: =!
- for /f "tokens=1* delims=:" %%k in ('nconvert.exe -info "%%b"^|findstr /i /l /c:"Height"') do set H=%%l&set H=!H: =!
- if !W! leq !H! (set W=0&set H=!str!) else (set W=!str!&set H=0)
- nconvert -rmeta -quiet -overwrite -out jpeg -ratio -resize !W! !H! -c 8 -o "%%a\%%~nb.jpg" "%%~nxb"
- )
- popd
- )
- echo.
- echo,修改图片完成. . .
- pause&exit /b
复制代码
|