add compress_assets target to compress PNG.

It depends on zopflipng, find and xargs.
Only zopflipng is tested, since it is the less common.
This commit is contained in:
Adrien CLERC 2019-09-02 22:16:08 +02:00 committed by Alexis Metaireau
parent 604f4696d8
commit 4a7c9d541d

View file

@ -6,6 +6,7 @@ DEV_STAMP = $(VENV)/.dev_env_installed.stamp
DOC_STAMP = $(VENV)/.doc_env_installed.stamp
INSTALL_STAMP = $(VENV)/.install.stamp
TEMPDIR := $(shell mktemp -d)
ZOPFLIPNG := zopflipng
.PHONY: all
all: install ## Alias for install
@ -47,6 +48,15 @@ test: $(DEV_STAMP) ## Run the tests
release: $(DEV_STAMP) ## Release a new version (see https://ihatemoney.readthedocs.io/en/latest/contributing.html#how-to-release)
$(VENV)/bin/fullrelease
.PHONY: compress_assets
compress_assets: ## Compress static assets
@which $(ZOPFLIPNG) >/dev/null || (echo "ZopfliPNG ($(ZOPFLIPNG)) is missing" && exit 1)
mkdir $(TEMPDIR)/zopfli
$(eval CPUCOUNT := $(shell python -c "import psutil; print(psutil.cpu_count(logical=False))"))
# We need to go into the directory to use an absolute path as a prefix
cd ihatemoney/static/images/; find -name '*.png' -printf '%f\0' | xargs --null --max-args=1 --max-procs=$(CPUCOUNT) $(ZOPFLIPNG) --iterations=500 --filters=01234mepb --lossy_8bit --lossy_transparent --prefix=$(TEMPDIR)/zopfli/
mv $(TEMPDIR)/zopfli/* ihatemoney/static/images/
.PHONY: build-translations
build-translations: ## Build the translations
$(VENV)/bin/pybabel compile -d ihatemoney/translations