Skip to content

Instantly share code, notes, and snippets.

@craigds
Created January 16, 2015 03:45
Show Gist options
  • Save craigds/d0c7ba50426ee159322a to your computer and use it in GitHub Desktop.
Save craigds/d0c7ba50426ee159322a to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import mapnik
import random
import time
w,h = 16,16
img = mapnik.Image(w,h)
img.background = mapnik.Color("white")
for x in range(0,16):
for y in range(0,16):
r = random.randint(0,255)
g = random.randint(0,255)
b = random.randint(0,255)
a = random.randint(0,255)
img.set_pixel(x,y,mapnik.Color(r,g,b,a))
img.save('out.png', 'png8:m=h')
start = time.time()
trials = 20000
for i in range(trials):
if i % 10000 == 0:
print i
img_data = img.tostring("png8:m=h")
print '%.3fs for %d trials' % ((time.time() - start), trials)
print '%d bytes' % len(img_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment