title: How can I convert my text string(which I think is a bytearray) to an image?
body: <p>I am trying to convert, what I think is a bytearray pulled from a database to an image using python PIL.</p>
  
  <p>I have access to the imagetype(jpg, png,..), the image height/width, and the bytearray. The bytearray is of the format </p>
  
  <blockquote>
    <p>0xffd8ffe000104a46494600010101006000600000ffe111164578.....</p>
  </blockquote>
  
  <p>I have tried many of the PIL options such as .fromstring and .frombuffer. I've also tried converting the bytearray into other forms (Base64,etc..) and then converting it to an image from there. None of these have worked and the image file is always corrupted.</p>
  
  <p>If i follow the advice from this <a href="https://stackoverflow.com/questions/18491416/pil-convert-bytearray-to-image">question</a>:</p>
  
  <pre><code>image = Image.open(io.BytesIO(imagestring))
  image.save(imageToSave.jpg)
  </code></pre>
  
  <p>I get this error: IOError: cannot identify image file</p>
  
  <p>type(imagestring) returns type 'bytearray'</p>
  
  <p>Thanks for reading and for any answers, let me know if I should edit this post with more info.</p>