title: Write PIL image to EXR using OpenEXR in Python
body: <p>I'm attempting to write a floating point PIL image object out to a channel in an EXR file using OpenEXR.</p>
  <p>I can read EXR data into a PIL image fine:</p>
  <pre><code>import OpenEXR
  import Imath
  from PIL import Image
  import numpy as np
  
  exrPath = &quot;path/to/image.exr&quot;
  exrFile = OpenEXR.InputFile(exrPath)
  
  pt = Imath.PixelType(Imath.PixelType.FLOAT)
  dw = curFile.header()['dataWindow']
  size = (dw.max.x - dw.min.x + 1, dw.max.y - dw.min.y + 1)
  
  rgbf = [Image.frombytes(&quot;F&quot;, size, exrFile.channel(c, pt)) for c in (&quot;R&quot;, &quot;G&quot;, &quot;B&quot;)]
  </code></pre>
  <p>I then run some operations over the PIL image data and want to save a single channel out as a new EXR.  This is what I have so far:</p>
  <pre><code>exrHeader = OpenEXR.Header(pilImage.size[0],pilImage.size[1])
  exrHeader[&quot;channels&quot;] = {&quot;GRAY&quot;:Imath.Channel(Imath.PixelType(Imath.PixelType.FLOAT), 1, 1)}
  
  exrOut = OpenEXR.OutputFile(&quot;path/to/new.exr&quot;, exrHeader)
  exrOut.writePixels({&quot;GRAY&quot;: np.array(pilImage).astype(np.float32).tostring()})
  </code></pre>
  <p>But I get this error:</p>
  <pre><code>TypeError: Data for channel 'GRAY' should have size 67108864 but got 16777216
  </code></pre>
  <p>How do I convert a floating point PIL image to the correct format to write to a float EXR channel?</p>