Skip to content

Instantly share code, notes, and snippets.

@imerr
Created May 10, 2015 17:20
Show Gist options
  • Save imerr/b06dabca6d7891d69130 to your computer and use it in GitHub Desktop.
Save imerr/b06dabca6d7891d69130 to your computer and use it in GitHub Desktop.
tiny image compression test
from PIL import Image
import random
import pylzma
for i in xrange(1000):
print i
img = Image.new("RGB", (16, 12))
data = img.load()
for x in range(16):
for y in range(12):
data[x,y] = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
img.save("bmp/{}.bmp".format(i))
img.save("gif/{}.gif".format(i))
img.save("jpg/{}.jpg".format(i))
img.save("png24/{}.png".format(i))
img.convert('P', palette=Image.ADAPTIVE).save("png8/{}.png".format(i))
with open("lzma/{}.xz".format(i), "wb") as f:
f.write(pylzma.compress(img.tobytes()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment