title: Receiving image from python child process to node, base64 encoding
body: <p>I'm having trouble sending an image encoded in base64 from a python child process to node. </p>
  
  <p>I am trying to:</p>
  
  <ul>
  <li>Spawn a child process in node to run a python file</li>
  <li>Open an image from python</li>
  <li>Rotate the image</li>
  <li>Encode the image</li>
  <li>Return the encoded string to node via stdout</li>
  <li>Receive the encoded string in node and write it to an image file.</li>
  </ul>
  
  <p>The python file is simple:</p>
  
  <pre><code>import sys
  from PIL import Image
  import base64
  import os
  
  ### Get image
  inputFilePath = sys.argv[1]
  img = Image.open(inputFilePath)
  
  ### Operate on image
  img = img.rotate(180)
  
  ### Save image
  img.save('temp_image.jpg')
  
  ### Convert image to base64
  with open('temp_image.jpg','rb') as imageFile:
      encodedString = base64.b64encode(imageFile.read())
  
      ### Remove Temp file
      os.remove('temp_image.jpg')
  
      ### send the base64 string to parent process
      print(encodedString)
  </code></pre>
  
  <p>This should send the encoded image to the parent process.</p>
  
  <p>In node, I'm trying to write the encoded string to an image file.</p>
  
  <pre><code>var spawn = child.spawn(cmd, args);
  
  var chunk = ''
  spawn.stdout.on('data', function(data){
    chunk += data.toString();
  });
  
  spawn.stdout.on('close', function(data){
    fs.writeFile(destination, chunk, 'base64', function(err){
        console.log("err: " + err)
      });
    });
    console.log("Done");
  });
  </code></pre>
  
  <p>My issue: the file is too small/otherwise corrupted. I'm not quite sure how to fix it- any help would be appreciated!</p>