Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use faster more effective lossless png optimizer (WIP) #347

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

montehurd
Copy link
Collaborator

@montehurd montehurd commented Jun 21, 2024

oxipng does multi-threaded lossless png optimizations, with one thread per cpu core by default - see its --threads param

so no longer need to use gnu parallel to achieve the same thing

( oxipng is a modern and actively maintained re-write of optipng )


benchmarks losslessly optimizing a set of 2004 unoptimized pixel screenshot pngs (on my local machine):

main branch
duration: 477 seconds
23.44% average size reduction

this simplify-png-optimizer branch
duration: 264 seconds
27.30% average reduction


ignore the first 5 commits - they were made irrelevant by the oxipng commit


easiest way to try this pr is to check out its branch then run ./rebuild.sh script. then you can run ./optimize-pngs.sh. just don't forget to run ./rebuild.sh again when you go back to main branch

No longer triggering optimization on png file
creation - this stability check was needed
because I think I was using inotifywait
incorrectly and it sometimes triggered when
the pngs were created (expected) but
also sometimes afterwards while they were being
written to. Perhaps related to writing exifdata?
No longer need -overwrite_original_in_place flag
because we're no longer worried about png creation
triggering optimization
@montehurd montehurd changed the title Greatly simplify png optimization Use faster more effective lossless png optimizer Jun 21, 2024
@montehurd
Copy link
Collaborator Author

montehurd commented Jun 21, 2024

i used this to calculate the average compression for main branch:

./optimize-pngs.sh | sed -n 's/.*Size reduction = \([0-9]*\.[0-9]*\)%.*/\1/p' | awk '{sum+=$1; count+=1} END {if (count > 0) print sum/count}'

and this to calculate the average compression for this pr (oxipng's stdout is slightly different):

./optimize-pngs.sh 2>&1 | sed -n 's/.*(\([0-9]*\.[0-9]*\)% smaller).*/\1/p' | awk '{sum+=$1; count+=1} END {if (count > 0) print sum/count}'

@montehurd montehurd changed the title Use faster more effective lossless png optimizer Use faster more effective lossless png optimizer (WIP) Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

1 participant