Convert 24-bit PNG files to 8-bit color indexed images with pypng

本小妞迷上赌 提交于 2020-07-19 12:05:27
问题 I'm trying to write a python script that takes in standard 24-bit pngs and converts them to 8-bit pngs for better compression. It looks like pypng can do this but I can't quite figure out how to use it. Image manipulation is a new area for me so this may seem silly. I have this currently: r=png.Reader(<myfile>) test = r.asRGBA8() This gives me tuples in return (the layers of the image I believe). However I can't seem to write or save this back to an image. What am I missing? Here's a test

Python base64 string to PyPng without saving file

三世轮回 提交于 2019-12-25 03:07:33
问题 How do you do this without saving to disk and then opening 'out.png' ? r = requests.get(url) mine,encoded = r.json()[0]['data'].split(',') #if it is segmentation decoded = base64.decodestring(encoded) if mine == 'data:image/png;base64': #TODO do this from memory g = open("out.png", "w") g.write(decoded) g.close() r = png.Reader('out.png') print 回答1: Use the bytes keyword r = png.Reader(bytes=decoded) 回答2: base53.decodestring() returns a string of the binary data, and according to