Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions benchmarks/img/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ def grouped(iterable, n):
total_initial_size = sum(pre_size_list)
total_final_size = sum(post_size_list)
delta = total_initial_size - total_final_size
total_percent = (total_final_size / total_initial_size) * 100

print(f"Total files: {len(percent_list)}")
print(f"\nInitial:\t{total_initial_size:>8} B")
print(f"Final: \t{total_final_size:>8} B")
print(f"Delta: -{delta} B")
print(f"Mean: {mean:.2f}%")
print(f"\nDelta: -{delta} B")
print(f"Total: {total_percent:.2f}% of initial size")
print(f"Mean image reduction: {mean:.2f}%")
try:
import numpy as np

Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 90
17 changes: 6 additions & 11 deletions src/crunch.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,7 @@ def main(argv):
# PNG validity test
if not is_valid_png(png_path):
sys.stderr.write(
ERROR_STRING
+ " '"
+ png_path
+ "' is not a valid PNG file."
+ os.linesep
ERROR_STRING + " '" + png_path + "' is not a valid PNG file." + os.linesep
)
if is_gui(argv):
log_error(png_path + " is not a valid PNG file.")
Expand Down Expand Up @@ -180,9 +176,7 @@ def main(argv):
+ os.linesep
)
if is_gui(argv):
log_error(
"pngquant was not found on the expected path " + PNGQUANT_EXE_PATH
)
log_error("pngquant was not found on the expected path " + PNGQUANT_EXE_PATH)
sys.exit(1)
elif not os.path.exists(ZOPFLIPNG_EXE_PATH):
sys.stderr.write(
Expand Down Expand Up @@ -239,6 +233,9 @@ def main(argv):
if is_gui(argv):
log_error(str(e))
sys.exit(1)
finally:
p.close()
p.join()

# end of successful processing, exit code 0
if is_gui(argv):
Expand Down Expand Up @@ -272,9 +269,7 @@ def optimize_png(png_path):
pngquant_options = (
" --quality=80-98 --skip-if-larger --force --strip --speed 1 --ext -crunch.png "
)
pngquant_command = (
PNGQUANT_EXE_PATH + pngquant_options + shellquote(img.pre_filepath)
)
pngquant_command = PNGQUANT_EXE_PATH + pngquant_options + shellquote(img.pre_filepath)
try:
subprocess.check_output(pngquant_command, stderr=subprocess.STDOUT, shell=True)
except CalledProcessError as cpe:
Expand Down
4 changes: 2 additions & 2 deletions src/install-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ PNGQUANT_EXE="$PNGQUANT_BUILD_DIR/pngquant"
ZOPFLIPNG_BUILD_DIR="$HOME/zopfli"
ZOPFLIPNG_EXE="$ZOPFLIPNG_BUILD_DIR/zopflipng"

PNGQUANT_VERSION_TAG="2.12.5"
ZOPFLIPNG_VERSION_TAG="v2.2.0"
PNGQUANT_VERSION_TAG="2.13.0"
ZOPFLIPNG_VERSION_TAG="v2.3.0"
LIBPNG_VERSION="1.6.37"
LIBPNG_VERSION_FILE="v$LIBPNG_VERSION.tar.gz"

Expand Down