首先,webp 的画质非常差,用 cwebp -mt -q 100 -m 6 -sharp_yuv -af -alpha_filter best -sns 0 压出来的 webp 都会与原图有放大后能够看到的明显区别,毕竟是 VP8 打底,最高水准也就那样了。当然,确实,体积小。
目前建议 jpegli. jpegli 的 q 90 感觉和上面那个各项打满的 q 100 的质量差不多。当然要求高一些的话可以往 q 95+ 走。
我有个自用的 batch 档,也是做转换和切割图片的——我不是 programmer, 真不是,而且 batch 纯自用,因此各种不足之处还请见谅了。不知道 V 站怎么贴,就试试看 markdown 了。
```
@
echo off
chcp 65001
setlocal enabledelayedexpansion
set "a="
set "i="
set "fn="
set "bn="
set "on="
set "gn="
set "np="
set "op="
set "cm="
set "sm="
set "hg="
set "jq="
set "wq="
set "sl="
set "sp="
set "ss="
set "sx="
set "sy="
set "cr1="
set "cr2="
set "cx1="
set "cx2="
set "sf1="
set "sf2="
set "cmb="
set "smb="
set "vfb="
set "cpf="
set "spf="
set "jpg="
set "png="
set "wbp="
set "sns="
:a
if "%~1"=="" goto p
set "a=%~1"
if "!a:~0,1!"=="-" (
if "!a!"=="-op" (set "np=%~2" & shift)
if "!a!"=="-on" (set "gn=%~2" & set "hg=1" & shift)
if "!a!"=="-ob" (set "bn=%~2" & shift)
if "!a!"=="-p" (set "png=1")
if "!a!"=="-wpq" (set "wbp=1" & set "sns=80" & set "wq=80")
if "!a!"=="-wlq" (set "wbp=1" & set "sns=50" & set "wq=85")
if "!a!"=="-wmq" (set "wbp=1" & set "sns=20" & set "wq=90")
if "!a!"=="-w" (set "wbp=1" & set "sns=0" & set "wq=95")
if "!a!"=="-whq" (set "wbp=1" & set "sns=0" & set "wq=99")
if "!a!"=="-jpq" (set "jpg=1" & set "jq=80")
if "!a!"=="-jlq" (set "jpg=1" & set "jq=85")
if "!a!"=="-jmq" (set "jpg=1" & set "jq=90")
if "!a!"=="-j" (set "jpg=1" & set "jq=95")
if "!a!"=="-jhq" (set "jpg=1" & set "jq=99")
if "!a!"=="-rg" (set "cm=rg" & set "cpf=rgr")
if "!a!"=="-cx" (set "cm=cx" & set "cx1=%~2" & set "cx2=%~3" & set "cpf=wth!cx1!t!cx2!" & shift & shift)
if "!a!"=="-cr" (set "cm=cr" & set "cr1=%~2" & set "cr2=%~3" & set "cpf=lts!cr1!t!cr2!" & shift & shift)
if "!a!"=="-gy" (set "cm=gy" & set "cpf=grv")
if "!a!"=="-gx" (set "cm=gx" & set "cpf=grh")
if "!a!"=="-gr" (set "cm=gr" & set "cpf=gr")
if "!a!"=="-sq" (set "cm=sq" & set "cpf=sq")
if "!a!"=="-up" (set "sm=up" & set "sp=%~2" & set "spf=!sp!pc" & shift)
if "!a!"=="-uf" (set "sm=uf" & set "sf1=%~2" & set "sf2=%~3" & set "spf=!sf1!d!sf2!" & shift & shift)
if "!a!"=="-uy" (set "sm=uy" & set "sy=%~2" & set "spf=x!sy!" & shift)
if "!a!"=="-ux" (set "sm=ux" & set "sx=%~2" & set "spf=!sx!x" & shift)
if "!a!"=="-us" (set "sm=us" & set "ss=%~2" & set "spf=s!ss!" & shift)
if "!a!"=="-ul" (set "sm=ul" & set "sl=%~2" & set "spf=l!sl!" & shift)
if "!a!"=="-sp" (set "sm=sp" & set "sp=%~2" & set "spf=!sp!pc" & shift)
if "!a!"=="-sf" (set "sm=sf" & set "sf1=%~2" & set "sf2=%~3" & set "spf=!sf1!d!sf2!" & shift & shift)
if "!a!"=="-sy" (set "sm=sy" & set "sy=%~2" & set "spf=x!sy!" & shift)
if "!a!"=="-sx" (set "sm=sx" & set "sx=%~2" & set "spf=!sx!x" & shift)
if "!a!"=="-ss" (set "sm=ss" & set "ss=%~2" & set "spf=s!ss!" & shift)
if "!a!"=="-sl" (set "sm=sl" & set "sl=%~2" & set "spf=l!sl!" & shift)
) else (
if not defined i set "i=%~1"
for %%f in ("!i!") do set "op=%%~dpf" & set "on=%%~nf"
)
shift
goto a
:p
if "!np!"=="" set "np=!op!"
if not "!np:~-1!"=="\" set "np=!np!\"
if not exist "!np!" md "!np!"
if "!bn!"=="" set "bn=!on!"
if defined cpf set "cpf=-!cpf!"
if defined spf set "spf=-!spf!"
if "!gn!"=="" set "gn=!bn!!cpf!!spf!"
if defined cm (
if "!cm!"=="cx" set "cmb=crop='floor(if(gte(iw/ih,!cx1!/!cx2!),ih*!cx1!/!cx2!,iw)/2)*2:floor(if(gte(iw/ih,!cx1!/!cx2!),ih,iw*!cx2!/!cx1!)/2)*2'"
if "!cm!"=="cr" set "cmb=crop='floor(if(gte(iw,ih),min(iw,ih*(!cr1!/!cr2!)),min(iw,ih*(!cr2!/!cr1!)))/2)*2:floor(if(gte(iw,ih),min(ih,iw*(!cr2!/!cr1!)),min(ih,iw*(!cr1!/!cr2!)))/2)*2'"
if "!cm!"=="rg" set "cmb=crop='floor(if(gte(iw,ih),min(iw,ih*(17711/28657)),min(iw,ih*(28657/17711)))/2)*2:floor(if(gte(iw,ih),min(ih,iw*(28657/17711)),min(ih,iw*(17711/28657)))/2)*2'"
if "!cm!"=="gy" set "cmb=crop='floor(if(gte(iw/ih,17711/28657),ih*17711/28657,iw)/2)*2:floor(if(gte(iw/ih,17711/28657),ih,iw*28657/17711)/2)*2'"
if "!cm!"=="gx" set "cmb=crop='floor(if(gte(iw/ih,28657/17711),ih*28657/17711,iw)/2)*2:floor(if(gte(iw/ih,28657/17711),ih,iw*17711/28657)/2)*2'"
if "!cm!"=="gr" set "cmb=crop='floor(if(gte(iw,ih),min(iw,ih*(28657/17711)),min(iw,ih*(17711/28657)))/2)*2:floor(if(gte(iw,ih),min(ih,iw*(17711/28657)),min(ih,iw*(28657/17711)))/2)*2'"
if "!cm!"=="sq" set "cmb=crop='floor(min(iw,ih)/2)*2:floor(min(iw,ih)/2)*2'"
)
if defined sm (
if "!sm!"=="sp" set "smb=scale='if(lte(!sp!,100),floor(iw*!sp!/100),iw):if(lte(!sp!,100),floor(ih*!sp!/100),ih)'"
if "!sm!"=="sf" set "smb=scale='if(lte(iw*!sf1!/!sf2!,iw),floor(iw*!sf1!/!sf2!),iw):if(lte(ih*!sf1!/!sf2!,ih),floor(ih*!sf1!/!sf2!),ih)'"
if "!sm!"=="sy" set "smb=scale='-2:if(lte(!sy!,ih),!sy!,ih)'"
if "!sm!"=="sx" set "smb=scale='if(lte(!sx!,iw),!sx!,iw):-2'"
if "!sm!"=="ss" set "smb=scale='if(lt(iw,ih),min(!ss!,iw),-2):if(gte(iw,ih),min(!ss!,ih),-2)'"
if "!sm!"=="sl" set "smb=scale='if(gte(iw,ih),min(!sl!,iw),-2):if(lt(iw,ih),min(!sl!,ih),-2)'"
if "!sm!"=="up" set "smb=scale='floor(iw*!sp!/100):floor(ih*!sp!/100)'"
if "!sm!"=="uf" set "smb=scale='floor(iw*!sf1!/!sf2!):floor(ih*!sf1!/!sf2!)'"
if "!sm!"=="uy" set "smb=scale=-2:!sy!"
if "!sm!"=="ux" set "smb=scale=!sx!:-2"
if "!sm!"=="us" set "smb=scale='if(lt(iw,ih),!ss!,-2):if(gte(iw,ih),!ss!,-2)'"
if "!sm!"=="ul" set "smb=scale='if(gte(iw,ih),!sl!,-2):if(lt(iw,ih),!sl!,-2)'"
)
if defined cm if not defined sm (set "vfb=!cmb!")
if not defined cm if defined sm (set "vfb=!smb!")
if defined cm if defined sm (set "vfb=!cmb!,!smb!")
if not defined vfb (
ffmpeg -i "!i!" -vframes:v 1 -update true -compression_level 0 "!op!!on!_intermediateagzk3kXe8nDr.png" -y
) else (
ffmpeg -i "!i!" -vframes:v 1 -update true -compression_level 0 -vf "!vfb!" -sws_flags lanczos+accurate_rnd+full_chroma_inp+full_chroma_int "!op!!on!_intermediateagzk3kXe8nDr.png" -y
)
if "!jpg!"=="1" (
cjpegli -q !jq! --chroma_subsampling=444 "!op!!on!_intermediateagzk3kXe8nDr.png" "!op!!on!_intermediateagzk3kXe8nDr.jpg"
exiftool -overwrite_original -all= "!op!!on!_intermediateagzk3kXe8nDr.jpg"
if "!hg!"=="1" (
move /y "!op!!on!_intermediateagzk3kXe8nDr.jpg" "!np!!gn!.jpg"
) else (
move /y "!op!!on!_intermediateagzk3kXe8nDr.jpg" "!np!!gn!-q!jq!.jpg"
)
)
if "!wbp!"=="1" (
cwebp -mt -q !wq! -m 6 -sharp_yuv -af -alpha_filter best -sns !sns! "!op!!on!_intermediateagzk3kXe8nDr.png" -o "!op!!on!_intermediateagzk3kXe8nDr.webp"
exiftool -overwrite_original -all= "!op!!on!_intermediateagzk3kXe8nDr.webp"
if "!hg!"=="1" (
move /y "!op!!on!_intermediateagzk3kXe8nDr.webp" "!np!!gn!.webp"
) else (
move /y "!op!!on!_intermediateagzk3kXe8nDr.webp" "!np!!gn!-q!wq!.webp"
)
)
if "!png!"=="1" (
optipng -o7 -zm1-9 "!op!!on!_intermediateagzk3kXe8nDr.png"
exiftool -overwrite_original -all= "!op!!on!_intermediateagzk3kXe8nDr.png"
move /y "!op!!on!_intermediateagzk3kXe8nDr.png" "!np!!gn!.png"
) else (
del /q "!op!!on!_intermediateagzk3kXe8nDr.png"
)
endlocal
```