Compress PNG images with `zopflipng`. #18661

pull mikispag wants to merge 1 commits into bitcoin:master from mikispag:master changing 87 files +0 −0
  1. mikispag commented at 10:02 PM on April 15, 2020: none

    Compress every PNG image with zopflipng, an open source program for losslessly compressing PNGs using DEFLATE better.

    This commit can be reproduced with the following command:

    for i in `find -type f -name '*.png'`; do zopflipng -m -y "$i" "$i" & done;
    

    and the latest version of zopflipng.

  2. Compress PNG images with zopflipng. 29e0336904
  3. MarcoFalke commented at 10:23 PM on April 15, 2020: member

    How much are the savings? For git the file size is going to effectively double, since it has to keep track of both versions.

    If the savings are worthwhile, I'd suggest to adjust our script to use zopfli: https://github.com/bitcoin/bitcoin/blob/master/contrib/devtools/optimize-pngs.py

  4. mikispag commented at 10:25 PM on April 15, 2020: none

    Good point. For some files, they become 25+% smaller.

  5. DrahtBot added the label Docs on Apr 15, 2020
  6. DrahtBot added the label GUI on Apr 15, 2020
  7. jonasschnelli commented at 6:45 AM on April 16, 2020: contributor

    Does this PR produce deterministic files? See discussion in #5489.

  8. mikispag commented at 7:18 AM on April 16, 2020: none

    I tried re-running several times and with the same version of zopflipng - yes. Not sure this is exactly what you are asking, though.

  9. promag commented at 9:34 AM on April 16, 2020: member

    No strong opinion, but I think savings aren't worth it.

  10. laanwj commented at 9:41 AM on April 16, 2020: member

    Tend toward NACK. Sorry to say, but reducing the size of our images to the absolute minimum is not an important concern of this project. There isn't much media in bitcoin core at all.

    If you want to do serious work in reducing the size of the distributed binaries, you might want to look at testing #18605.

  11. MarcoFalke removed the label Docs on Apr 16, 2020
  12. kiminuo commented at 1:51 PM on April 16, 2020: contributor

    I agree with laanwj.

  13. fanquake commented at 3:15 AM on April 17, 2020: member

    Thanks. This kind of thing has come up many times before, #16636, #11069, #17122, #14615, and it'd seem that if we were to merge a compression, 6 months later someone will likely be able to optimize the images slightly more (and we'd just end up with even more copies of the same files in git).

    If you are keen to start contributing, I'd suggest taking a look at the good first issues list.

  14. fanquake closed this on Apr 17, 2020

  15. MarcoFalke commented at 11:39 AM on April 17, 2020: member

    I was patching our script for fun to see if zopfli can improve on top of pngcrush, and it seems so. Not enough to change anything in our repo, but enough to entertain me for 12 minutes running a script.

    Total reduction: 43655 bytes
    

    Also, the checksum was stable after two runs.

    Diff I used: (Could potentially be enhanced by keeping pngcrush as a preprocessing step)

    diff --git a/contrib/devtools/optimize-pngs.py b/contrib/devtools/optimize-pngs.py
    index e9481dbbcf..e665541a8c 100755
    --- a/contrib/devtools/optimize-pngs.py
    +++ b/contrib/devtools/optimize-pngs.py
    @@ -24,7 +24,7 @@ def content_hash(filename):
         data = i.tobytes()
         return hashlib.sha256(data).hexdigest()
     
    -pngcrush = 'pngcrush'
    +pngcrush = 'zopflipng'
     git = 'git'
     folders = ["src/qt/res/movies", "src/qt/res/icons", "share/pixmaps"]
     basePath = subprocess.check_output([git, 'rev-parse', '--show-toplevel'], universal_newlines=True, encoding='utf8').rstrip('\n')
    @@ -43,17 +43,12 @@ for folder in folders:
                 fileMetaMap['contentHashPre'] = content_hash(file_path)
     
                 try:
    -                subprocess.call([pngcrush, "-brute", "-ow", "-rem", "gAMA", "-rem", "cHRM", "-rem", "iCCP", "-rem", "sRGB", "-rem", "alla", "-rem", "text", file_path],
    +                subprocess.call([pngcrush, '-m', '-y', file_path, file_path],
                                     stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
                 except:
                     print("pngcrush is not installed, aborting...")
                     sys.exit(0)
     
    -            #verify
    -            if "Not a PNG file" in subprocess.check_output([pngcrush, "-n", "-v", file_path], stderr=subprocess.STDOUT, universal_newlines=True, encoding='utf8'):
    -                print("PNG file "+file+" is corrupted after crushing, check out pngcursh version")
    -                sys.exit(1)
    -
                 fileMetaMap['sha256New'] = file_hash(file_path)
                 fileMetaMap['contentHashPost'] = content_hash(file_path)
     
    
  16. MarcoFalke commented at 11:39 AM on April 17, 2020: member

    So Concept ACK the next time we change the icons in the GUI, but Concept NACK for now.

  17. DrahtBot locked this on Feb 15, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-21 18:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me