add pngquant support

This commit is contained in:
Christopher Monsanto
2020-09-16 05:33:44 -04:00
parent cf3a9cb8ff
commit 0807f9c85b
2 changed files with 12 additions and 9 deletions

View File

@@ -10,6 +10,7 @@ This project depends on
- [ImageMagick](http://www.imagemagick.org/) >= 7
- [AdvPng](http://www.advancemame.it/doc-advpng.html) (optional)
- [OptiPNG](http://optipng.sourceforge.net/) (optional)
- [pngquant](https://pngquant.org/) (optional)
- [pnpm](https://pnpm.js.org)
- [node.js](https://nodejs.org) >= 13
- [wine](https://www.winehq.org/) (optional)
@@ -21,7 +22,7 @@ Windows binaries of these dependencies can be found on the download pages of the
### Linux
```
$ sudo apt install nodejs imagemagick advancecomp optipng wine
$ sudo apt install nodejs imagemagick advancecomp optipng pngquant wine
$ sudo npm install -g pnpm
```
@@ -54,7 +55,7 @@ Using [`brew`](https://brew.sh/) on a macOS:
```
$ brew cask install osxfuse wine-stable
$ brew install tup imagemagick advancecomp optipng
$ brew install tup imagemagick advancecomp optipng pngquant
```
## Building
@@ -71,6 +72,7 @@ Build settings are configurable in `tup.config`.
- `CONFIG_DEFAULT_OPTIPNG`: Command line to pass to `optipng`.
- `CONFIG_DEFAULT_ADVPNG`: Command line to pass to `advpng`.
- `CONFIG_DEFAULT_PNGQUANT`: Command line to pass to `pngquant`.
- `CONFIG_DEFAULT_DEFLOPT`: `true`, `false`, or blank
There are src-specific versions of these settings:

View File

@@ -24,22 +24,23 @@ function trimimg(opts) -- Can't just be trim because of the string function...
}
end
local DEFAULT_OPTIPNG = getconfig("DEFAULT_OPTIPNG")
local DEFAULT_ADVPNG = getconfig("DEFAULT_ADVPNG")
local DEFAULT_DEFLOPT = booleanconfig("DEFAULT_DEFLOPT")
function compresspng(opts)
local cmds = {}
local output = opts.output or "%o"
local optipng = DEFAULT_OPTIPNG
local advpng = DEFAULT_ADVPNG
local deflopt = DEFAULT_DEFLOPT
local pngquant = getconfig("DEFAULT_PNGQUANT")
local optipng = getconfig("DEFAULT_OPTIPNG")
local advpng = getconfig("DEFAULT_ADVPNG")
local deflopt = booleanconfig("DEFAULT_DEFLOPT")
if opts.config then
pngquant = getconfig(opts.config .. "_PNGQUANT") or pngquant;
optipng = getconfig(opts.config .. "_OPTIPNG") or optipng;
advpng = getconfig(opts.config .. "_ADVPNG") or advpng;
deflopt = booleanconfig(opts.config .. "_DEFLOPT") or deflopt;
end
if pngquant then
cmds += rep{"pngquant ${opts} ${output}", opts=pngquant, output=output}
end
if optipng then
cmds += rep{"optipng -q ${opts} ${output}", opts=optipng, output=output}
end