0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-08 16:00:19 -05:00

Merge branch 'rhcarvalho-zopflipng' into develop

This commit is contained in:
Andrés Moya 2022-02-09 15:13:53 +01:00
commit 4856413b24
17 changed files with 62 additions and 0 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 114 KiB

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 898 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3 KiB

After

Width:  |  Height:  |  Size: 765 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 814 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4 KiB

After

Width:  |  Height:  |  Size: 900 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 199 KiB

After

Width:  |  Height:  |  Size: 172 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 13 KiB

62
frontend/scripts/compress-png Executable file
View file

@ -0,0 +1,62 @@
#!/usr/bin/env bash
# This script automates compressing PNG images using the lossless Zopfli
# Compression Algorithm. The process is slow but can produce significantly
# better compression and, thus, smaller file sizes.
#
# This script is meant to be run manually, for example, before making a new
# release.
#
# Requirements
#
# zopflipng - https://github.com/google/zopfli
# Debian/Ubuntu: sudo apt install zopfli
# Fedora: sudo dnf install zopfli
# macOS: brew install zopfli
#
# Usage
#
# This script takes a single positional argument which is the path where to
# search for PNG files. By default, the target path is the current working
# directory. Run from the root of the repository to compress all PNG images. Run
# from the `frontend` subdirectory to compress all PNG images within that
# directory. Alternatively, run from any directory and pass an explicit path to
# `compress-png` to limit the script to that path/directory.
set -o errexit
set -o nounset
set -o pipefail
readonly TARGET="${1:-.}"
readonly ABS_TARGET="$(command -v realpath &>/dev/null && realpath "$TARGET")"
function png_total_size() {
find "$TARGET" -type f -iname '*.png' -exec du -ch {} + | tail -1
}
echo "Compressing PNGs in ${ABS_TARGET:-$TARGET}"
echo "Before"
png_total_size
readonly opts=(
# More iterations means slower, potentially better compression.
#--iterations=500
-m
# Try all filter strategies (slow).
#--filters=01234mepb
# According to docs, remove colors behind alpha channel 0. No visual
# difference, removes hidden information.
--lossy_transparent
# Avoid information loss that could affect how images are rendered, see
# https://github.com/penpot/penpot/issues/1533#issuecomment-1030005203
# https://github.com/google/zopfli/issues/113
--keepchunks=cHRM,gAMA,pHYs,iCCP,sRGB,oFFs,sTER
# Since we have git behind our back, overwrite PNG files in-place (only
# when result is smaller).
-y
)
time find "$TARGET" -type f -iname '*.png' -exec zopflipng "${opts[@]}" {} {} \;
echo "After"
png_total_size