@rem (作为一个集图爱好者,喜欢收藏各类图集;但有的图只大了却质量不好,丢之可惜,^
放着太占地方,只有调整大小了;^
集图的原则:保持图集的完整性与原始性.原始性只有牺牲一下了.)- @goto start
- :help
- @echo.===== Ver: 1.1 =========================== 发布日期: 2010-09-24 =======
- @echo. BAT_NAME: 图片大小调整.bat
- @echo. 返回值:
- @echo. 作用 : 图片大小调整
- @echo. 调用: 图片大小调整.bat [Path...] [file...]
- @echo. [Path]: 文件夹路径
- @echo. [file]: 文件
- @echo. 注:关键控制参数:短边的最小像素 %minpix%,小于等于的不予处理;
- @echo.====================== Copyright@ by hf-g ========= [彭城] ============
- ping /n 4 127.0>nul
- goto:end
- :start ============================================================
- @echo off&setlocal
- path=%path%;%~d0\DOS\command\第三方命令行程序
- set "nconvert=g:\DOS\command\第三方命令行程序\nconvert.exe"
- ::标准屏幕尺寸:
- ::19寸宽屏的液晶 1440*900=1.6=8:5
- ::17或19的液晶 1280/1024=1.25=5:4
- ::20"普屏液晶 1600/1200=4:3 1400/1050=4:3
- ::800/600=4:3 1024/768=4:3 2880/1920=1.5=3:2
- ::常见图片分辨率:
- ::3060/4590=1.5=3:2 2020/3030=3:2
- ::长边的最小像素
- ::set/a maxpix=
- ::★短边的最小像素
- set/a minpix=2020
- ::==================ADD REG===============================
- for /f "skip=4 tokens=3" %%a in ('REG QUERY "HKLM\Software\hf'file" /v resize_pic 2^>nul') do set KEY_v=%%a
- if "%KEY_v%" LSS "1" (
- reg add "HKLM\SOFTWARE\Classes\Directory\shell\图片大小调整&S\command" /ve /d "\"%~f0\" \"%%1\"" /f>nul
- reg add "HKLM\SOFTWARE\Classes\jpegfile\shell\图片大小调整&S\command" /ve /d "\"%~f0\" \"%%1\"" /f>nul
- reg add "HKLM\Software\hf'file" /v resize_pic /d 1 /f>nul
- )
- ::========================================================
- if /i "%~1"=="" goto help
- if /i "%~1"=="-?" goto help
- set "ext="&set "pathname="&set "Dir_name="&set "p_str="
- set /a exit_BL=0,D_count=0,f_count=0
-
- call:get_P %*
- if "%exit_BL%"=="1" goto end
-
- ::设置临时文件
- ::set "tmpfname=%~dp0.\%~n0.log"
- ::cd.>"%tmpfname%"
- ::echo 生成日志文件: %tmpfname%
- echo 正在处理:
- ::========================MAIN============================
- set/a D_count-=1,f_count-=1
- if not "%pathname_0%"=="" (
- set "ext=*.jpg *.bmp"
- for /l %%i in (0,1,%D_count%) do (
- call pushd "%%pathname_%%i%%"
- call echo %%pathname_%%i%%:
- for /f "tokens=* delims=" %%i in ('dir /a-d/b/s %ext%') do (
- for /f "tokens=1,2 delims=: " %%a in ('%nconvert% -info "%%i"^|findstr /i "Width Height"') do (
- if /i "%%a"=="Width" set "pciW=%%b"
- if /i "%%a"=="Height" set "pciH=%%b"
- )
- call call:resize_pic "%%pciW%%" "%%pciH%%" "%%i"
- )
- popd
- ))
-
- if not "%file_0%"=="" (
- for /l %%i in (0,1,%f_count%) do (
- for /f "tokens=1,2 delims=: " %%a in ('%nconvert% -info "%%file_%%i%%"^|findstr /i "Width Height"') do (
- if /i "%%a"=="Width" set "pciW=%%b"
- if /i "%%a"=="Height" set "pciH=%%b"
- )
- call call:resize_pic "%%pciW%%" "%%pciH%%" "%%file_%%i%%"
- )
- )
-
- :end ==============================================================
- ::if exist "%tmpfname%" del "%tmpfname%" "%~dp0.\del_list.bat"
- exit /b
- ::=================================================================
- :resize_pic Width Height picfname
- if %~1 GTR %minpix% (
- set/p =%~1x%~2 %~nx3<nul
- rem echo %~1x%~2 %~3>>"%tmpfname%"
- if %~1 GEQ %~2 (
- rem 横式图,且高度大于"短边的最小像素"
- rem if %~2 GTR %minpix% %nconvert% -quiet -out jpeg -ratio -resize 0 %minpix% -o $%%_1 "%~3"
- if %~2 GTR %minpix% %nconvert% -quiet -out jpeg -ratio -resize 0 %minpix% -o $%% "%~3"
- ) else (
- rem 竖式图,且宽度大于"短边的最小像素"
- rem %nconvert% -quiet -out jpeg -ratio -resize %minpix% 0 -o $%%_1 "%~3"
- %nconvert% -quiet -out jpeg -ratio -resize %minpix% 0 "%~3"
- )
- )
-
-
- goto:eof
- ::========================参数设置与获得============================
- :get_p
- ::判断%1是文件夹或文件
- if "%~1"=="" goto:eof
- set "p_str=%~1"
- if exist "%p_str%" (
- if exist "%p_str%.\" (
- call set "pathname_%%D_count%%=%p_str%"&set /a D_count+=1&shift /1&goto get_p
- )
- call set "file_%%f_count%%=%p_str%"&set /a f_count+=1&shift /1&goto get_p
- ) else (
- echo %p_str% 不是一个正确的文件夹路径或文件^!&set /a exit_BL=1&shift /1&goto end
- )
- @echo off
- :get_p_end
- goto:eof
复制代码 补充 nconvert 工具下载:
http://bbs.bathome.net/thread-4567-1-1.html |