R
R
Rrooom2014-08-21 17:32:38
Django
Rrooom, 2014-08-21 17:32:38

How to save an image as a line in a file?

To avoid unnecessary requests to the file system, I want to store a one-pixel png directly in the file, but how to do it right?
No matter how I ... suffered, in the browser - "cannot be shown, as it contains errors." Although in theory everything should be true - print repr(open('r.png', 'rb').read())well, I assigned the printed line to the answer.

a = '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08\x04\x00\x00\x00\xb5\x1c\x0c\x02\x00\x00\x00\x0bIDAT\x08\xd7c``\x00\x00\x00\x03\x00\x01 \xd5\x94\xc7\x00\x00\x00\x00IEND\xaeB`\x82'

return HttpResponse(a, content_type="image/png)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sakuradaj, 2014-08-21
@sakuradaj

Try storing data in base64

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question