From 560ea4f76cb520208769561b4061b4f42dbaed2a Mon Sep 17 00:00:00 2001 From: Aditya Rakhecha Date: Fri, 7 Sep 2018 00:51:33 +0530 Subject: [PATCH 01/12] Updated with color box --- templates/tools/Colors_tools/rgb2hsv.html | 31 ++++++++++++++++++----- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/templates/tools/Colors_tools/rgb2hsv.html b/templates/tools/Colors_tools/rgb2hsv.html index 3349526..5ff659a 100644 --- a/templates/tools/Colors_tools/rgb2hsv.html +++ b/templates/tools/Colors_tools/rgb2hsv.html @@ -20,9 +20,12 @@ B - - - + + + + + + @@ -58,6 +61,15 @@ var b = document.getElementById("RGB").rows[1].cells[2].firstChild.value; + if ( r == null || g == null || b == null || isNaN(r) || isNaN(g)|| isNaN(b) ) { + alert ('Please enter numeric RGB values!'); + return; + } + if (r < 0 || g < 0 || b < 0 || r > 255 || g > 255 || b > 255) { + alert ('RGB values must be in the range 0 to 255.'); + return; + } + r = r / 255; g = g / 255; b = b / 255; @@ -68,14 +80,14 @@ v = rgbMax; var delta = rgbMax - rgbMin; - + if(rgbMax != 0) s = delta / rgbMax; else { s = 0; h = 0; - //alert("Input values are not correct"); + return; } if(r == rgbMax) @@ -92,9 +104,16 @@ document.getElementById("HSV").rows[1].cells[0].firstChild.value = h; document.getElementById("HSV").rows[1].cells[1].firstChild.value = (s * 100).toFixed(2); document.getElementById("HSV").rows[1].cells[2].firstChild.value = (v * 100).toFixed(2); + } + function showColor(){ + var r = document.getElementById("RGB").rows[1].cells[0].firstChild.value; + + var g = document.getElementById("RGB").rows[1].cells[1].firstChild.value; + + var b = document.getElementById("RGB").rows[1].cells[2].firstChild.value; - } + document.getElementById("RGB").rows[2].cells[0].style.backgroundColor = 'rgb('+r+' , '+g+' , '+b+')'; {% endblock %} From 18b50f6803f4d242be398a51d790792b254f9d88 Mon Sep 17 00:00:00 2001 From: Aditya Rakhecha Date: Thu, 13 Sep 2018 21:20:16 +0530 Subject: [PATCH 02/12] Update tool_views.py --- mainapp/tool_views.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/mainapp/tool_views.py b/mainapp/tool_views.py index 5fc2e72..5d67c93 100644 --- a/mainapp/tool_views.py +++ b/mainapp/tool_views.py @@ -24,6 +24,7 @@ import sys from django.core.files.storage import FileSystemStorage import time +import cv2 as cv @@ -69,6 +70,34 @@ def convert_file(request): return HttpResponse('Error while converting', status=404) +def convert_image(request): + if request.method=='POST': + image_to_convert = request.FILES.get('image') + convert_to = request.POST.get('convert_to') + + filename, ext = os.path.splitext(image_to_convert.name) + outputfile_name = '{0}.{1}'.format(filename, convert_to) + input_file_path = os.path.join(settings.MEDIA_ROOT, 'files', image_to_convert.name) + output_file_path = os.path.join(settings.MEDIA_ROOT, 'files', outputfile_name) + path = default_storage.save(input_file_path, ContentFile(image_to_convert.read())) + + inpImage = cv.imread("lena.tif",1) + + inpImage2 = inpImage + imgBilFilter = cv.bilateralFilter(inpImage2, 9,9,7) + + imgGray = cv.cvtColor(imgBilFilter, cv.COLOR_RGB2GRAY) + + imgfilter = cv.medianBlur(imgGray, 5) + + imgEdge = cv.adaptiveThreshold(imgfilter, 255, cv.ADAPTIVE_THRESH_MEAN_C, + cv.THRESH_BINARY, 9, 2); + imgColored = cv.cvtColor(imgEdge, cv.COLOR_GRAY2RGB) + + imgFinal = cv.bitwise_and(inpImage, imgColored) + + cv.imshow("Final", imgFinal) + cv.waitKey(0) def jpg_to_png(request): if request.method=="POST": @@ -187,4 +216,4 @@ def view_generated_pdf(request,path): return response raise HttpResponse('file Not Found') - \ No newline at end of file + From 51ff4f69374532b55c8a3b86ce35c8fdde5b8682 Mon Sep 17 00:00:00 2001 From: Aditya Rakhecha Date: Thu, 13 Sep 2018 21:20:53 +0530 Subject: [PATCH 03/12] Update urls.py --- mainapp/urls.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mainapp/urls.py b/mainapp/urls.py index fa4be1f..00fd4f8 100644 --- a/mainapp/urls.py +++ b/mainapp/urls.py @@ -5,6 +5,7 @@ from django.conf import settings urlpatterns = [ +url(r'^convert_image/$',tool_views.convert_image,name='convert_image'), url(r'^convert_file/$',tool_views.convert_file,name='convert_file'), url(r'^minify/$', tool_views.show_minified_js,name = 'show_minified_js'), url(r'^minify_file/$', tool_views.download_minified_file, name = 'download_minified_JS'), From 9f74262075f6c578010a0a8a9012ee285fd7f954 Mon Sep 17 00:00:00 2001 From: Aditya Rakhecha Date: Thu, 13 Sep 2018 21:21:52 +0530 Subject: [PATCH 04/12] Create cartoonify.html --- templates/tools/image_tools/cartoonify.html | 34 +++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 templates/tools/image_tools/cartoonify.html diff --git a/templates/tools/image_tools/cartoonify.html b/templates/tools/image_tools/cartoonify.html new file mode 100644 index 0000000..aa8ca58 --- /dev/null +++ b/templates/tools/image_tools/cartoonify.html @@ -0,0 +1,34 @@ +{% extends "tools/tool_base.html" %} +{% load staticfiles %} + + + +{% block tool %} + +
+ {%csrf_token%} + + + +
+ +{% endblock %} + + +{% block scripts %} + + + +{% endblock %} From beb12e80a60f16f025511b1d683513094c330fd7 Mon Sep 17 00:00:00 2001 From: Aditya Rakhecha Date: Fri, 14 Sep 2018 00:49:53 +0530 Subject: [PATCH 05/12] Update tool_views.py --- mainapp/tool_views.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/mainapp/tool_views.py b/mainapp/tool_views.py index 5d67c93..abdfa75 100644 --- a/mainapp/tool_views.py +++ b/mainapp/tool_views.py @@ -81,23 +81,25 @@ def convert_image(request): output_file_path = os.path.join(settings.MEDIA_ROOT, 'files', outputfile_name) path = default_storage.save(input_file_path, ContentFile(image_to_convert.read())) - inpImage = cv.imread("lena.tif",1) - + inpImage = cv.imread(input_file_path,1) inpImage2 = inpImage imgBilFilter = cv.bilateralFilter(inpImage2, 9,9,7) - imgGray = cv.cvtColor(imgBilFilter, cv.COLOR_RGB2GRAY) - imgfilter = cv.medianBlur(imgGray, 5) - imgEdge = cv.adaptiveThreshold(imgfilter, 255, cv.ADAPTIVE_THRESH_MEAN_C, cv.THRESH_BINARY, 9, 2); imgColored = cv.cvtColor(imgEdge, cv.COLOR_GRAY2RGB) - imgFinal = cv.bitwise_and(inpImage, imgColored) + cv.imwrite('01.png', imgFinal) + + if os.path.exists(output_file_path): + print('exists') + with open(output_file_path, 'rb+') as fh: + response = HttpResponse(fh.read(), content_type="application/force-download") + response['Content-Disposition'] = 'inline; filename=' + os.path.basename(output_file_path) + return response - cv.imshow("Final", imgFinal) - cv.waitKey(0) + return HttpResponse('Error while converting', status=404) def jpg_to_png(request): if request.method=="POST": From 5ec647718feea65f81bb576121cc80746e8def2f Mon Sep 17 00:00:00 2001 From: Aditya Rakhecha Date: Tue, 18 Sep 2018 18:06:52 +0530 Subject: [PATCH 06/12] Update tool_views.py --- mainapp/tool_views.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/mainapp/tool_views.py b/mainapp/tool_views.py index abdfa75..6a8da44 100644 --- a/mainapp/tool_views.py +++ b/mainapp/tool_views.py @@ -77,8 +77,8 @@ def convert_image(request): filename, ext = os.path.splitext(image_to_convert.name) outputfile_name = '{0}.{1}'.format(filename, convert_to) - input_file_path = os.path.join(settings.MEDIA_ROOT, 'files', image_to_convert.name) - output_file_path = os.path.join(settings.MEDIA_ROOT, 'files', outputfile_name) + input_file_path = os.path.join(settings.MEDIA_ROOT, 'cartoonify/input', image_to_convert.name) + output_file_path = os.path.join(settings.MEDIA_ROOT, 'cartoonify/output', outputfile_name) path = default_storage.save(input_file_path, ContentFile(image_to_convert.read())) inpImage = cv.imread(input_file_path,1) @@ -90,16 +90,10 @@ def convert_image(request): cv.THRESH_BINARY, 9, 2); imgColored = cv.cvtColor(imgEdge, cv.COLOR_GRAY2RGB) imgFinal = cv.bitwise_and(inpImage, imgColored) - cv.imwrite('01.png', imgFinal) + cv.imwrite("media/cartoonify/output/convertedImg.png", imgFinal) + return render(request,'tools/image_tools/cartoonify.html',{'output_file_path': "media/cartoonify/output/convertedImg.png" }) - if os.path.exists(output_file_path): - print('exists') - with open(output_file_path, 'rb+') as fh: - response = HttpResponse(fh.read(), content_type="application/force-download") - response['Content-Disposition'] = 'inline; filename=' + os.path.basename(output_file_path) - return response - - return HttpResponse('Error while converting', status=404) + return HttpResponse('Error while converting', status=404) def jpg_to_png(request): if request.method=="POST": From fbfc3dd8be33f6d0dc85c4089a90d89c9c5933af Mon Sep 17 00:00:00 2001 From: Aditya Chatterjee Date: Sat, 29 Sep 2018 20:29:16 +0530 Subject: [PATCH 07/12] fixed location for saved file --- mainapp/tool_views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mainapp/tool_views.py b/mainapp/tool_views.py index 6a8da44..9fb5e3f 100644 --- a/mainapp/tool_views.py +++ b/mainapp/tool_views.py @@ -90,8 +90,8 @@ def convert_image(request): cv.THRESH_BINARY, 9, 2); imgColored = cv.cvtColor(imgEdge, cv.COLOR_GRAY2RGB) imgFinal = cv.bitwise_and(inpImage, imgColored) - cv.imwrite("media/cartoonify/output/convertedImg.png", imgFinal) - return render(request,'tools/image_tools/cartoonify.html',{'output_file_path': "media/cartoonify/output/convertedImg.png" }) + cv.imwrite(settings.MEDIA_ROOT+"/cartoonify/output/convertedImg.png", imgFinal) + return render(request,'tools/image_tools/cartoonify.html') return HttpResponse('Error while converting', status=404) From 30f5a7594f6bd6dc4ed14ac6f77b5db6f070b32a Mon Sep 17 00:00:00 2001 From: Aditya Chatterjee Date: Sat, 29 Sep 2018 20:29:46 +0530 Subject: [PATCH 08/12] fixed type --- templates/tools/image_tools/cartoonify.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/tools/image_tools/cartoonify.html b/templates/tools/image_tools/cartoonify.html index aa8ca58..7e29005 100644 --- a/templates/tools/image_tools/cartoonify.html +++ b/templates/tools/image_tools/cartoonify.html @@ -7,7 +7,7 @@
{%csrf_token%} - +
From a7bdf6efee38665faac7e9657f89409e03fd9566 Mon Sep 17 00:00:00 2001 From: Aditya Rakhecha Date: Sat, 29 Sep 2018 23:13:03 +0530 Subject: [PATCH 09/12] cartoonify_output.html added --- .../tools/image_tools/cartoonify_output.html | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 templates/tools/image_tools/cartoonify_output.html diff --git a/templates/tools/image_tools/cartoonify_output.html b/templates/tools/image_tools/cartoonify_output.html new file mode 100644 index 0000000..d7d8176 --- /dev/null +++ b/templates/tools/image_tools/cartoonify_output.html @@ -0,0 +1,20 @@ +{% extends "tools/tool_base.html" %} +{% load staticfiles %} + + + +{% block tool %} + + + + + + + + + + +
InputOutput
output image
+{% endblock %} + + From 99d21814eae92ec5d988172fa19fbd28ce7fe711 Mon Sep 17 00:00:00 2001 From: Aditya Rakhecha Date: Sat, 29 Sep 2018 23:14:58 +0530 Subject: [PATCH 10/12] render statement update --- mainapp/tool_views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mainapp/tool_views.py b/mainapp/tool_views.py index 9fb5e3f..361d5cd 100644 --- a/mainapp/tool_views.py +++ b/mainapp/tool_views.py @@ -91,7 +91,8 @@ def convert_image(request): imgColored = cv.cvtColor(imgEdge, cv.COLOR_GRAY2RGB) imgFinal = cv.bitwise_and(inpImage, imgColored) cv.imwrite(settings.MEDIA_ROOT+"/cartoonify/output/convertedImg.png", imgFinal) - return render(request,'tools/image_tools/cartoonify.html') + return render(request,'tools/image_tools/cartoonify_output.html', {'input_file': input_file_path, + 'output_file': settings.MEDIA_ROOT+"/cartoonify/output/convertedImg.png"}) return HttpResponse('Error while converting', status=404) From bc6e7ed20e49610d9feaf46bc0d8b0fa75d035ef Mon Sep 17 00:00:00 2001 From: Aditya Rakhecha Date: Sun, 30 Sep 2018 00:02:38 +0530 Subject: [PATCH 11/12] button added --- templates/tools/image_tools/cartoonify_output.html | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/templates/tools/image_tools/cartoonify_output.html b/templates/tools/image_tools/cartoonify_output.html index d7d8176..caee52e 100644 --- a/templates/tools/image_tools/cartoonify_output.html +++ b/templates/tools/image_tools/cartoonify_output.html @@ -14,7 +14,18 @@ output image + + + {% endblock %} +{% block scripts %} + +{% endblock %} From d633711cb6c87ff609bd493d72d55eeebec8d71a Mon Sep 17 00:00:00 2001 From: Aditya Rakhecha Date: Sun, 30 Sep 2018 22:11:04 +0530 Subject: [PATCH 12/12] download button added --- templates/tools/image_tools/cartoonify_output.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/templates/tools/image_tools/cartoonify_output.html b/templates/tools/image_tools/cartoonify_output.html index caee52e..7e56dd4 100644 --- a/templates/tools/image_tools/cartoonify_output.html +++ b/templates/tools/image_tools/cartoonify_output.html @@ -15,7 +15,8 @@ output image - + + {% endblock %}