{% extends "introduction/base.html" %} {% load static %} {% block content %} {% block title %} A9 {% endblock %}

In this page you can upload a image and apply different math equation on it's rgb layer



Varriable reffernence

img --> actual image file | r --> red chennel | g --> green chennel b --> blue chennel | g --> green chennel

Some Example



{% if success %}
{% endif %}
This lab uses pillow==8.0.0 package, google for vulnerability
def a9_lab2(request):
 if not request.user.is_authenticated:
  return redirect('login')

 if request.method == "GET":
  return render (request,"Lab/A9/a9_lab2.html")
 elif request.method == "POST":
  try :
   file=request.FILES["file"]
   function_str = request.POST.get("function")
   img = Image.open(file)
   img = img.convert("RGB")
   r,g,b = img.split()
   output = ImageMath.eval(function_str,img = img, b=b, r=r, g=g)
   # saving the image
   buffered = BytesIO()
   output.save(buffered, format="JPEG")
   img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
   bufferd_ref = BytesIO()
   img.save(bufferd_ref, format="JPEG")
   img_str_ref = base64.b64encode(bufferd_ref.getvalue()).decode("utf-8")
   try :
    return render(request,"Lab/A9/a9_lab2.html",{"img_str": img_str,"img_str_ref":img_str_ref, "success": True})
   except Exception as e:
    print(e)
    return render(request, "Lab/A9/a9_lab2.html", {"data": "Error", "error": True})
  except Exception as e:
   print(e)
   return render(request, "Lab/A9/a9_lab2.html", {"data":"Please Upload a file", "error":True})
{% endblock %}