0

Im new to stackoverflow and this will be my first quastion. I will try to explain my problem as good as I can.

Im doing python code for a server. Where I load an image and do a lot of image processing on it. It ends up as a np.array binary mask (that can be converted to an Image object if needed). Now I need to encode this image in base64, to send it to client with json. On the client side it's not python code and it have to be decoded and readable as a normal image format. I have only find examples for encoding a image that is loaded directly from a file. So a solution is to save it as a temp image, then load this image and encode it. But this is very ugly. There must be a way to directly encode it and specify what image format you want to encode it as?

5
  • 1
    Does this previous answer of mine help? Commented Apr 23, 2013 at 8:13
  • I think it helps, I tried it and then decoded the image back again do verify. But the output image looks abit wierd. But maybe my decodeing is the problem. The code looks like this: <code> test_img = Image.fromarray(back_seg*255) # from np.array output = StringIO() test_img.save(output, format='JPEG') im_data = output.getvalue() data_url = base64.b64encode(im_data) g = open("out.JPEG", "w") g.write(data_url.decode('base64')) g.close() </code> Commented Apr 23, 2013 at 9:06
  • Encode, to a data: URL, then paste that into your browser to verify the image. Commented Apr 23, 2013 at 9:07
  • Thanks, that works. Sry for not finding that question myself. So how do I close this question? Commented Apr 23, 2013 at 9:48
  • I've voted to close it as a duplicate, which pushes it into the review queue. Commented Apr 23, 2013 at 10:17

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.