def image_colorize(original, randomize=True, color=(255, 255, 255)):
 original = Image.open(StringIO.StringIO(original))
 image = Image.new('RGB', original.size)
 if randomize:
  color = (randrange(32, 224, 24), randrange(32, 224, 24), randrange(32, 224, 24))
 image.paste(color, box=((0, 0) + original.size))
 image.paste(original, mask=original)
 buffer = StringIO.StringIO()
 image.save(buffer, 'PNG')
 return buffer.getvalue()

def image_colorize ( original , randomize = True , color = ( 255 , 255 , 255 ) ) : original = Image . open ( StringIO . StringIO ( original ) ) image = Image . new ( 'RGB' , original . size ) if randomize : color = ( randrange ( 32 , 224 , 24 ) , randrange ( 32 , 224 , 24 ) , randrange ( 32 , 224 , 24 ) ) image . paste ( color , box = ( ( 0 , 0 ) + original . size ) ) image . paste ( original , mask = original ) buffer = StringIO . StringIO ( ) image . save ( buffer , 'PNG' ) return buffer . getvalue ( )
add a color to the transparent background of an image .