Commits

Gregory Petukhov  committed c011a2c

Add bgcolor argument to image.random_image function

  • Participants
  • Parent commits b784ea9

Comments (0)

Files changed (2)

File common/image.py

     return 'rgb(%d, %d, %d)' % (randint(0, 255), randint(0, 255), randint(0, 255))
 
 
-def generate_image(size):
+def generate_image(size, bgcolor='#000000'):
     img = Image.new('RGBA', size=size)
     draw = ImageDraw.Draw(img)
+    draw.rectangle(((0, 0), size), fill=bgcolor)
     for x in xrange(30):
         diameter = int(min(*size) / float(randint(4, 8)))
         topleft = (0 + randint(0, size[0]),
     return img
 
 
-def random_image(size=(200, 200)):
+def random_image(size=(200, 200), bgcolor='#000000'):
     source = '%d%d' % (time.time(), id({}))
     hashname = sha1(source).hexdigest() + '.jpg'
     tmpfile = NamedTemporaryFile()
-    img = generate_image(size)
+    img = generate_image(size, bgcolor)
     img.save(tmpfile, 'JPEG')
     tmpfile.seek(0)
     return File(tmpfile, name=hashname)
 from setuptools import setup
 
 PACKAGE = 'common'
-VERSION = '0.1.41'
+VERSION = '0.1.42'
 
 if __name__ == '__main__':
     # Compile the list of packages available, because distutils doesn't have