title: Rasterio MemoryFile to Pillow image (Or base64 output)
body: <p>I'm trying to write an AWS Lambda function that takes a TIFF, converts it to JPEG, then outputs it in base64 so that lambda can serve it. But I keep running into malformed response, or issues with <code>reshape_as_image</code> saying axes doesn't match array.</p>
  <p>My understanding was that the return of <code>memfile.read()</code> would allow me to use reshape_as_image, however my logic seems faulty.</p>
  <p>Without saving to disk, how can I get from memfile to a base64 jpeg representation so that lambda can serve it? I've also tried pillow but I think the necessary step is where I'm failing.</p>
  <pre><code>    def get_image(self, driver=&quot;jpeg&quot;):
          data = self.get_image()
  
          with MemoryFile() as memfile:
              # Change the driver for output
              data[1]['driver'] = driver
          with MemoryFile() as memfile:
              # Change the driver for output
              data[1]['driver'] = driver
  
              with memfile.open(**data[1]) as dataset:
                  dataset.write(data[0])
                  
              image = memfile.read()
              image = reshape_as_image(image)
              im = Image.open(io.BytesIO(image))
              b64data = base64.b64encode(im.tobytes()).decode('utf-8')
              return b64data
  </code></pre>