PNG optimisation tools

前端 未结 4 678
-上瘾入骨i
-上瘾入骨i 2020-12-08 08:53

A while back I used a PNG optimisation service called (I think) \"smush it\". You fed it a weblink and it returned a zip of all the PNG images with their filesizes nicely, w

4条回答
  •  情歌与酒
    2020-12-08 09:20

    I would question the wisdom of throwing away other chunks (like gAMA and iCCP), but if that's what you want to do it's fairly easy to use PyPNG to remove chunks:

    #!/usr/bin/env python
    import png
    import sys
    
    input=sys.stdin
    out=sys.stdout
    
    def critical_chunks(chunks):
        for type,data in chunks:
            if type[0].isupper():
                yield type,data
    
    chunks = png.Reader(file=input).chunks()
    png.write_chunks(out, critical_chunks(chunks))
    

    the critical_chunks function is essentially filtering out all but the critical PNG chunks (the 4 letter type for a critical chunk starts with an uppercase letter).

提交回复
热议问题