title: Python: How to turn an IMAGE into a STRING and back?
body: <p>I have an <strong>image</strong> like this loaded into a <code>PIL.Image</code>:  </p>
  
  <h2><a href="https://i.stack.imgur.com/OPuDy.png" rel="noreferrer"><img src="https://i.stack.imgur.com/OPuDy.png" alt="enter image description here"></a></h2>
  
  <p>And now I want to turn it into a <strong>python string</strong>, and it should not be binary, how do I do this?
  Because when I tried to encode I get the following error:</p>
  
  <p><strong>My Code:</strong></p>
  
  <pre><code>from PIL import Image
  
  img = Image.open("testImage.jpeg")
  string = img.tobytes()
  string = string.decode("ascii")
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>Traceback (most recent call last):
    File "/Users/tomschimansky/Desktop/SenderMAIN.py", line 5, in &lt;module&gt;
      string = string.decode("ascii")
  UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)
  </code></pre>
  
  <p>When this works I also want to turn the string <strong>back into an image</strong>.</p>
  
  <p><strong>Other methods</strong> that <strong>also don't worke</strong>d for me:</p>
  
  <ul>
  <li>Read the image directly from file with <code>open("file","rb")</code> and then encode it.</li>
  <li>encode it with the <code>codecs</code> library. (<code>string = codecs.encode(string, "base64"</code>))</li>
  <li>encode it with the <code>base64</code> library (was able to convert it to string but the string looked like this: <code>///////</code>. (only slashes))</li>
  </ul>
  
  <p>Thanks for your Answers!</p>