diff --git a/benchmarks/img/bench.py b/benchmarks/img/bench.py index 3df643c..f12fc15 100644 --- a/benchmarks/img/bench.py +++ b/benchmarks/img/bench.py @@ -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 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..43d7a3a --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[flake8] +max-line-length = 90 diff --git a/src/crunch.py b/src/crunch.py index 6282dde..45c2700 100755 --- a/src/crunch.py +++ b/src/crunch.py @@ -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.") @@ -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( @@ -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): @@ -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: diff --git a/src/install-dependencies.sh b/src/install-dependencies.sh index ba10eda..c6f7fd0 100755 --- a/src/install-dependencies.sh +++ b/src/install-dependencies.sh @@ -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"