我想压缩目录中存在的所有TRUE
图像文件,并使用pngquant将所有这些转换/压缩的图像文件保存到其原始图像名称的不同文件夹中:
批量压缩的语法:
png
它压缩pngquant.exe --quality=40-55 images\*.png
目录中的所有PNG图像文件,并将压缩文件保存为同一目录中的新文件,并在原始文件名后附加 -fs8 ,例如
images
arrow.png
arrow-fs8.png
是源文件,arrow.png
是输出文件。
我想将所有已转换的文件及其原始名称保存在单独的文件夹中。
有人知道如何使用pngquant.exe吗?
arrow-fs8.png
使用选项pngquant
运行它时帮助输出:
-h
答案 0 :(得分:1)
以下是具有其他功能的任务的注释批处理代码。
@echo off
setlocal
rem It is expected that pngquant.exe is in same directory as the
rem batch file and %~dp0 returns this path ending with a backslash.
set "ToolPath=%~dp0"
rem Use as source directory either the first specified parameter
rem on calling this batch file or the current working directory.
set "SourceFolder=%~f1"
if "%SourceFolder%" == "" set "SourceFolder=%CD%"
rem Replace all slashes by backslashes.
set "SourceFolder=%SourceFolder:/=\%"
rem Remove last character if it is a backslash.
if "%SourceFolder:~-1%" == "\" set "SourceFolder=%SourceFolder:~0,-1%"
rem Use as output directory either the second specified parameter
rem on calling this batch file or the current working directory.
set "OutputFolder=%~f2"
if "%OutputFolder%" == "" set "OutputFolder=%CD%"
set "OutputFolder=%OutputFolder:/=\%"
if "%OutputFolder:~-1%" == "\" set "OutputFolder=%OutputFolder:~0,-1%"
rem Set source directory as current directory. The source directory
rem can be also specified with an UNC path which is the reason why
rem command PUSHD is used and not command CD.
pushd "%SourceFolder%"
rem Either optimize all PNG files in source directory with output
rem also in source directory using default new file name or process
rem in a loop each PNG file separately with writing the optimized
rem image to output directory with same name as source file.
if /I "%SourceFolder%" == "%OutputFolder%" (
"%ToolPath%pngquant.exe" --quality=40-55 --force *.png
) else (
if not exist "%OutputFolder%" (
md "%OutputFolder%"
if errorlevel 1 (
echo Failed to create the output folder:
echo.
echo %OutputFolder%
echo.
pause
goto RestoreEnviroment
)
)
for %%I in (*.png) do (
"%ToolPath%pngquant.exe" --quality=40-55 --force --output "%OutputFolder%\%%I" "%%I"
)
)
:RestoreEnviroment
rem Restore the previous current directory and delete the local copy of
rem the environment variables table, i.e. restore previous environment.
popd
endlocal
可以在启动/调用此批处理文件时将源文件夹指定为第一个参数,将输出文件夹指定为第二个参数。
如果源文件夹与批处理文件应该是同一个文件夹,并且只应在启动/调用此批处理文件时指定输出文件夹,请为当前文件夹指定.
作为第一个参数。
要了解使用的命令及其工作原理,请打开命令提示符窗口,执行以下命令,并完全阅读为每个命令显示的所有帮助页面。
echo /?
endlocal /?
for /?
goto /?
if /?
md /?
pause /?
popd /?
pushd /?
rem /?
set /?
setlocal /?
pngquant.exe -h