I have converted image to base64 string using following code. Based on this string want to create Image object and want to add some headers to it like ,
Expires: Mon, 29 Apr 2013 21:44:55 GMT Cache-Control: max-age=0, no-cache, no-store ,
and print that object as a image to the django template.
Is it possible in django ?
Here is the code to convert img from url to base64.
import mimetypes
import urllib2
def stringifyImage(url):
tmpdir = 'tmp'
mmtp = mimetypes.guess_type(url, strict=True)
if not mmtp[0]:
return False
ext = mimetypes.guess_extension(mmtp[0])
f = open(tmpdir+'tmp'+ext,'wb')
f.write(urllib2.urlopen(url).read())
f.close()
img = open(tmpdir+'tmp'+ext, "rb").read().encode("base64").replace("\n","")
return img