批处理之家's Archiver

hfg1977 发表于 2010-9-24 22:34

批处理调整图片大小

@rem (作为一个集图爱好者,喜欢收藏各类图集;但有的图只大了却质量不好,丢之可惜,^
放着太占地方,只有调整大小了;^
集图的原则:保持图集的完整性与原始性.原始性只有牺牲一下了.)[code]@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[/code]补充 nconvert 工具下载:
[url=http://bbs.bathome.net/thread-4567-1-1.html]http://bbs.bathome.net/thread-4567-1-1.html[/url]

bbwanwt123 发表于 2010-10-1 14:55

运行不了啊············

自动关闭了

Batcher 发表于 2010-10-1 18:54

回复 2楼 的帖子

你有nconvert.exe么?放在哪个目录?

523066680 发表于 2010-10-1 20:15

楼主不给力啊,给个三方工具的下载外链+说明一下也行啊
set "nconvert=g:\DOS\command\第三方命令行程序\nconvert.exe"

百度一下,这老帖不得了……
http://www.cn-dos.net/forum/blog.php?tid=25914&uid=51697

[[i] 本帖最后由 523066680 于 2010-10-1 20:20 编辑 [/i]]

qq15700 发表于 2022-3-26 14:51

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=61396&ptid=9398]3#[/url] [i]Batcher[/i] [/b]


    应该放在哪个目录,然后我拖动文件夹到bat上 不识别,拖动多个照片文件,只有最后一个照片文件转换后有后缀,前面几个都只转换,生成没有后缀的文件

Batcher 发表于 2022-3-26 15:15

[b]回复 [url=http://bbs.bathome.net/redirect.php?goto=findpost&pid=253259&ptid=9398]5#[/url] [i]qq15700[/i] [/b]


    时间比较久远了,不确定楼主还能否看到你的问题反馈。建议新开一个帖子详细说说自己的需求吧。

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.