Skip to content

Instantly share code, notes, and snippets.

@juanplopes
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save juanplopes/4d68dd7276ba97c7c6c3 to your computer and use it in GitHub Desktop.

Select an option

Save juanplopes/4d68dd7276ba97c7c6c3 to your computer and use it in GitHub Desktop.
Python script to put a rainbow overlay in an image
#!/usr/bin/env python
import Image, colorsys, sys
if len(sys.argv) < 2:
print 'usage: {} <file> [<output>]'.format(sys.argv[0])
sys.exit(0)
img = Image.open(sys.argv[1])
width, height = img.size
for i in xrange(width):
for j in xrange(height):
pixel = img.getpixel((i,j))
rbow = colorsys.hsv_to_rgb((j/float(height)-0.05)%1.0, 1, 1)
img.putpixel((i, j), tuple(int((a+b*255)/2) for a, b in zip(pixel, rbow)))
outfile = sys.argv[2] if len(sys.argv) >= 3 else 'rainbow_' + sys.argv[1]
img.save(outfile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment