Skip to content

Instantly share code, notes, and snippets.

@Leonidas-from-XIV
Created February 7, 2012 09:37
Show Gist options
  • Save Leonidas-from-XIV/1758713 to your computer and use it in GitHub Desktop.
Save Leonidas-from-XIV/1758713 to your computer and use it in GitHub Desktop.
Generator for random JPEG images
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
from itertools import izip
from datetime import datetime
from PIL import Image
from numpy.random import randint
x, y = 2560, 1920
def grouper(n, iterable):
args = [iter(iterable)] * n
return izip(*args)
def rndnumpy(pixels):
rand = randint(0, 255, pixels*3)
return grouper(3, rand)
img = Image.new('RGB', (x, y))
img.putdata(list(rndnumpy(x*y)))
img.save(datetime.now().strftime('IMG_%Y%m%d_%H%M%S.jpg'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment