2016-05-02 11 views
3

私は、ディレクトリ内に存在する全てのpng画像ファイルを圧縮し、pngquantを使用して、元の画像の名前を持つ別のフォルダにすべてのこれらの変換/圧縮された画像ファイルを保存したい:バッチ圧縮のためPNGQUANTでバッチPNG圧縮を実行し、変換されたすべてのイメージをソース名で別のフォルダに保存する方法はありますか?

構文:

pngquant.exe --quality=40-55 images\*.png 

imagesディレクトリにあるすべてのPNG画像ファイルを圧縮し、元のファイル名の後ろに-fs8を追加して、同じディレクトリに圧縮ファイルを新しいファイルとして保存します。

arrow.png 
arrow-fs8.png 

arrow.pngソースファイルとarrow-fs8.pngは、出力ファイルです。

変換されたすべてのファイルを元の名前で別のフォルダに保存します。

pngquant.exeでこれを行う方法を知っている人はいますか?オプション-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. 
+1

あなたの質問を編集して、この外部コマンドライン 'pngquant.exe'の助けを投稿することができますか? – Hackoo

答えて

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 

このバッチファイルを呼び出す/起動の2番目のパラメータとして最初のパラメータと出力フォルダとしてソースフォルダを指定することが可能です。

ソースフォルダがバッチファイルと同じフォルダで、このバッチファイルの開始/呼び出し時に出力フォルダのみを指定する必要がある場合は、最初のパラメータとして現在のフォルダの.を指定します。

使用されているコマンドとその動作方法を理解するには、コマンドプロンプトウィンドウを開き、次のコマンドを実行して、コマンドごとに表示されているすべてのヘルプページをすべてよく読んでください。

  • echo /?
  • endlocal /?
  • for /?
  • goto /?
  • if /?
  • md /?
  • pause /?
  • popd /?
  • pushd /?
  • rem /?
  • set /?
  • setlocal /?
  • pngquant.exe -h
関連する問題