#!/usr/bin/env python

# write16.py: example of writing 16-bit grayscale PNG
# Gordon Kindlmann
#
# version 0.1, Mon Oct 11 13:30 CDT 2010

import Image, numpy

# Data numpy array is created as 32-bit int, rather than the 16-bit that we 
# intend to save out, since the "fromarray" function seems to assume
# that as part of how it gets values from memory.
ramp_data =  numpy.zeros((32,256),dtype=numpy.int32)

# filling in values with linear ramp
for i in range(256):
  ramp_data[:,i] = i*256

# Without the mode='I', Image will be 8-bit rather than 16-bit image
# One might also try Image.fromarray(ramp_data).convert('I'), but I
# couldn't get this to work reliably
io = Image.fromarray(ramp_data,mode='I')
io.save("ramp.png")
