Image 如何使用PNGQUANT执行批处理PNG压缩,并将所有转换的图像及其源名称保存到另一个文件夹?

Image 如何使用PNGQUANT执行批处理PNG压缩,并将所有转换的图像及其源名称保存到另一个文件夹?,image,batch-file,pngquant,Image,Batch File,Pngquant,我想压缩目录中存在的所有png图像文件,并使用以下方法将所有这些转换/压缩的图像文件保存到具有原始图像名称的不同文件夹中: 批处理压缩的语法: pngquant.exe --quality=40-55 images\*.png 它压缩images目录中的所有PNG图像文件,并将压缩文件作为新文件保存在同一目录中,在原始文件名后附加-fs8,例如 arrow.png arrow-fs8.png arrow.png是源文件,arrow-fs8.png是输出文件 我想将所有转换后的文件及其原始名称

我想压缩目录中存在的所有
png
图像文件,并使用以下方法将所有这些转换/压缩的图像文件保存到具有原始图像名称的不同文件夹中:

批处理压缩的语法:

pngquant.exe --quality=40-55 images\*.png
它压缩
images
目录中的所有PNG图像文件,并将压缩文件作为新文件保存在同一目录中,在原始文件名后附加-fs8,例如

arrow.png
arrow-fs8.png
arrow.png
是源文件,
arrow-fs8.png
是输出文件

我想将所有转换后的文件及其原始名称保存在单独的文件夹中

有人知道怎么用它吗

使用选项
-h
运行时,通过
pngquant
帮助输出:

pngquant, 2.5.2 (October 2015), by Greg Roelofs, Kornel Lesinski.
   Compiled without support for color profiles. Using libpng 1.6.18.

usage:  pngquant [options] [ncolors] -- pngfile [pngfile ...]
        pngquant [options] [ncolors] - >stdout <stdin

options:
  --force           overwrite existing output files (synonym: -f)
  --skip-if-larger  only save converted files if they're smaller than original
  --output file     destination file path to use instead of --ext (synonym: -o)
  --ext new.png     set custom suffix/extension for output filenames
  --quality min-max don't save below min, use fewer colors below max (0-100)
  --speed N         speed/quality trade-off. 1=slow, 3=default, 11=fast & rough
  --nofs            disable Floyd-Steinberg dithering
  --posterize N     output lower-precision color (e.g. for ARGB4444 output)
  --verbose         print status messages (synonym: -v)

Quantizes one or more 32-bit RGBA PNGs to 8-bit (or smaller) RGBA-palette.
The output filename is the same as the input name except that
it ends in "-fs8.png", "-or8.png" or your custom extension (unless the
input is stdin, in which case the quantized image will go to stdout).
The default behavior if the output file exists is to skip the conversion;
use --force to overwrite. See man page for full list of options.
pngquant,2.5.2(2015年10月),作者格雷格·罗洛夫斯,科内尔·莱辛斯基。
编译时不支持颜色配置文件。使用libpng 1.6.18。
用法:pngquant[options][ncolors]--pngfile[pngfile…]

pngquant[options][ncolors]->stdout这里是带有附加功能的任务的注释批处理代码

@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
启动/调用此批处理文件时,可以将源文件夹指定为第一个参数,将输出文件夹指定为第二个参数

如果源文件夹应与批处理文件位于同一文件夹中,并且在启动/调用此批处理文件时只应指定一个输出文件夹,请为当前文件夹指定第一个参数just

要了解所使用的命令及其工作方式,请打开命令提示符窗口,在其中执行以下命令,并非常仔细地阅读为每个命令显示的所有帮助页面

  • echo/?
  • endlocal/?
  • 获取/?
  • goto/?
  • 如果/?
  • md/?
  • 暂停/?
  • popd/?
  • pushd/?
  • rem/?
  • 设置/?
  • setlocal/?
  • pngquant.exe-h

您是否可以编辑您的问题并发布此外部命令行的帮助
pngquant.exe