DJANGO image processing
Xristos Xristoou
saxri89 at gmail.com
Sat Feb 11 13:34:52 EST 2017
I want to create a django app with the base64 help where the users can upload images(specific ".tiff" ext) using DJANGO forms without model and without that images store in my server. and i will the users can be get back new processing image.
i have success with encode/decode image with base64 and i can display that image in template using safari because that can display TIFF images.
here the code :
views.py
def convert_to_base64(image_file):
base64_string = base64.encodestring(image_file)
return "data:image/png;base64,"+base64_string
@csrf_exempt
def index(request):
form = ImageUploadForm(request.POST or None, request.FILES or None)
if request.method == "POST" and form.is_valid():
image_file = request.FILES['image'].read()
base64_string = convert_to_base64(image_file)
file = base64_string.decode('utf8')
return render_to_response("blog/success.html", {"image_file":file})
return render_to_response('blog/calc.html', {'form': form}, RequestContext(request))
my problem is now after the base64 i cant use that image for image processing(work fine in standalone python script) and i take two error :
RuntimeError at /
not a string in the browser
and that message in command line :
"GET / HTTP/1.1" 200 346
ERROR 4: `II*' does not exist in the file system,
and is not recognised as a supported dataset name.
here the code :
@csrf_exempt
def index(request):
form = ImageUploadForm(request.POST or None, request.FILES or None)
if request.method == "POST" and form.is_valid():
image_file = request.FILES['image'].read()
base64_string = convert_to_base64(image_file)
file = base64_string.decode('utf8')
file_like = cStringIO.StringIO(image_file)
flow_direction_uri = "output.tif"
routing.flow_direction_d_inf(file_like, flow_direction_uri)
return render_to_response("blog/success.html", {"image_file":file})
return render_to_response('blog/calc.html', {'form': form}, RequestContext(request))
and if i use file = base64_string.decode('utf8') as input in my function then i take that error :
AttributeError at /
'NoneType' object has no attribute 'GetRasterBand'
and in command line i take to like that :
AIAAgACAAIAAgACAAIAAgACAAIAAgACA
AIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAA
gACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACA
AIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAA
with to many lines.
More information about the Python-list
mailing list