def selectimage(request): ip = get_client_ip(request) widthImage = 1024 heightImage = 768 pathFix = setpath() path1 = str(pathFix + "/chequeApp/static/" + ip + "/abc.jpg") img = PythonMagick.Image(path1) img.read(path1) # read in at 300 dpi imageSize = img.size() print "*******crop image", imageSize.height( ), "*****crop image", imageSize.width() crpImageHeight = imageSize.height() crpImageWidth = imageSize.width() widthRatio = int(crpImageWidth / widthImage) heightRatio = int(crpImageHeight / heightImage) if request.method == 'POST': x1 = request.POST['x1'] x2 = request.POST['x2'] y1 = request.POST['y1'] y2 = request.POST['y2'] mainImgPath = str(pathFix + "/chequeApp/static/" + ip + "/abc.jpg") img = Image.open(mainImgPath) imgCrop = img.crop((int(x1), int(y1), int(x2), int(y2))) cropImgPath = str(pathFix + "/chequeApp/static/" + ip + "/abcCrop.jpg") imgCrop.save(cropImgPath) print x1, x2, y1, y2 return render(request, 'chequeApp/selectPixel.html', { 'x1': x1, 'y1': y1, 'x2': x2, 'y2': y2 }) else: return render(request, 'chequeApp/selectPixel.html')
def mutualUpload(request): # Handle file upload form = MutualDataForm() pathFix = setpath() print "mutual entry", time.ctime() if os.path.isdir(pathFix + '/document/mutualequity'): for i in glob.glob(pathFix + '/document/mutualequity/*'): os.remove(i) #shutil.rmtree('/home/puneet/Desktop/deepak/Projects/mysite/document/bo/') #shutil.rmtree('/home/puneet/Desktop/deepak/Projects/mysite/document/ucc/') if request.method == 'POST': cid = request.POST['cid'] pwd = request.POST['pwd'] print "in post --- ", cid, "pwd", pwd form = MutualDataForm(request.POST, request.FILES) if form.is_valid(): instance = MutualDataUpload(mutualfile=request.FILES['mutualfile']) instance.save() address = "" if os.path.isdir(pathFix + '/document/mutualequity'): for i in glob.glob(pathFix + '/document/mutualequity/*'): address = i print address if os.path.isdir('%s/chequeApp/static/%s' % (pathFix, cid)) == True: os.system( "pdftk %s input_pw %s output %s/chequeApp/static/%s/crack.pdf" % (address, pwd, pathFix, cid)) else: os.mkdir('%s/chequeApp/static/%s' % (pathFix, cid)) os.system( "pdftk %s input_pw %s output %s/chequeApp/static/%s/crack.pdf" % (address, pwd, pathFix, cid)) #split PDF and convert it into image imglist = splitpdfintoimages( cid, '%s/chequeApp/static/%s' % (pathFix, cid)) if os.path.isdir('%s/chequeApp/static/%s/output' % (pathFix, cid)) == False: os.mkdir('%s/chequeApp/static/%s/output' % (pathFix, cid)) shutil.make_archive( pathFix + '/chequeApp/static/imgFile', 'zip', pathFix + '/chequeApp/static/' + cid + '/imgFile/') """filename = pathFix + '/mysite/chequeApp/static/imgFile.zip' wrapper = FileWrapper(file(filename)) response = HttpResponse(wrapper, content_type='application/x-zip-compressed') response['Content-Length'] = os.path.getsize(filename) response['Content-Disposition'] = 'attachment; filename="result.zip"'""" print "mutual Exit", time.ctime() return HttpResponse("SUCCESSFULLY STORED+" + cid + "+" + str(imglist)) else: HttpResponse("Error during Upload") HttpResponse("Error during Upload")
def selectimagetestNewAjaxCrop(request): import pdb pdb.set_trace() ip = get_client_ip(request) data12 = {} imgid = 0 pathFix = setpath() if request.method == 'POST': print 'post call' print request.body data12 = request.body ip = (data12.split('=')[2]).split('&')[-2] imgid = (data12.split('=')[1]).split('&')[-2] print ip, '-------', imgid widthImage = 1024.0 heightImage = 768.0 path1 = str(pathFix + "/chequeApp/static/" + ip + "/abc%s.jpg" % (imgid)) img = PythonMagick.Image(path1) img.read(path1) # read in at 300 dpi imageSize = img.size() print "*******crop image", imageSize.height( ), "*****crop image", imageSize.width() crpImageHeight = imageSize.height() * 1.0 crpImageWidth = imageSize.width() * 1.0 widthRatio = crpImageWidth / widthImage heightRatio = crpImageHeight / heightImage print widthRatio, '*****', heightRatio if request.method == 'POST': #form = DocumentForm(request.POST, request.FILES) x1 = float( (data12.split('=')[3]).split('&')[-2]) #(request.POST['x1']) x2 = float( (data12.split('=')[5]).split('&')[-2]) #(request.POST['x2']) y1 = float( (data12.split('=')[4]).split('&')[-2]) #(request.POST['y1']) y2 = float((data12.split('=')[-1])) #(request.POST['y2']) mainImgPath = str(pathFix + "/chequeApp/static/" + ip + "/abc%s.jpg" % (imgid)) img = Image.open(mainImgPath) print x1, y1, x2, y2 imgCrop = img.crop((int(x1 * widthRatio), int(y1 * heightRatio), int(x2 * widthRatio), int(y2 * heightRatio))) cropImgPath = str(pathFix + "/chequeApp/static/" + ip + "/abcCrop%s.jpg" % (imgid)) imgCrop.save(cropImgPath) #return render(request, 'chequeApp/chequeApp.html', # {'form': form, 'ip': ip, 'x1': x1, 'y1': y1, 'x2': x2, 'y2': y2}) print 'if Ajax Crop ', ip return HttpResponse(ip) else: form = DocumentForm() #return render(request, 'chequeApp/chequeApp.html', {'form': form, 'ip': ip}) #data = xyzCrop(appname, ip) data = "Error" print 'else', ip return HttpResponse(ip)
def selectimagetestNew(request): ip = get_client_ip(request) data12 = {} pathFix = setpath() if request.method == 'POST': print 'post call' print request.body data12 = request.body ip = (data12.split('=')[-2]).split('&')[-2] print ip widthImage = 1024.0 heightImage = 768.0 path1 = str(pathFix + "/chequeApp/static/" + ip + "/abc.jpg") img = PythonMagick.Image(path1) img.read(path1) # read in at 300 dpi imageSize = img.size() print "*******crop image", imageSize.height( ), "*****crop image", imageSize.width() crpImageHeight = imageSize.height() * 1.0 crpImageWidth = imageSize.width() * 1.0 widthRatio = crpImageWidth / widthImage heightRatio = crpImageHeight / heightImage print widthRatio, '*****', heightRatio if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) x1 = float(request.POST['x1']) x2 = float(request.POST['x2']) y1 = float(request.POST['y1']) y2 = float(request.POST['y2']) mainImgPath = str(pathFix + "/chequeApp/static/" + ip + "/abc.jpg") img = Image.open(mainImgPath) print x1, y1, x2, y2 imgCrop = img.crop((int(x1 * widthRatio), int(y1 * heightRatio), int(x2 * widthRatio), int(y2 * heightRatio))) cropImgPath = str(pathFix + "/chequeApp/static/" + ip + "/abcCrop.jpg") imgCrop.save(cropImgPath) return render(request, 'chequeApp/chequeApp.html', { 'form': form, 'ip': ip, 'x1': x1, 'y1': y1, 'x2': x2, 'y2': y2 }) else: form = DocumentForm() return render(request, 'chequeApp/chequeApp.html', { 'form': form, 'ip': ip })
def downloadFile(request): analysisData() pathFix = setpath() shutil.make_archive(pathFix + '/mysite/document/result', 'zip', pathFix + '/mysite/document/output/') filename = pathFix + '/mysite/document/result.zip' wrapper = FileWrapper(file(filename)) response = HttpResponse(wrapper, content_type='application/x-zip-compressed') response['Content-Length'] = os.path.getsize(filename) response['Content-Disposition'] = 'attachment; filename="result.zip"' # shutil.rmtree('/home/puneet/Desktop/deepak/Projects/mysite/document/bo/') # shutil.rmtree('/home/puneet/Desktop/deepak/Projects/mysite/document/ucc/') return response
def mutualimageupload(request): # ip = get_client_ip(request) # if request.COOKIES['username'] # print x # ip = get_client_ip(request) data1 = {} imgid = 0 pathfix = setpath() if request.method == 'POST': print 'post call' print request.body data1 = request.body imgid = data1.split('=')[-1] ip = (data1.split('=')[1]).split('&')[0] print ip, '---', imgid path1 = pathfix + "/chequeApp/static/" + ip + "/imgFile/page_-" + imgid + ".jpg" t = handle_uploaded_fileX(path1, ip) return HttpResponse(t) else: return HttpResponse("error happen")
def handle_uploaded_file2(f, ip): list1 = [] print ' handle_uploaded_file2', ip path = "" pathFix = setpath() for i in glob.glob(pathFix + '/chequeApp/static/*'): list1.append(i.split('/')[-1]) if ip not in list1: os.mkdir(pathFix + '/chequeApp/static/%s' % (ip)) path = pathFix + '/chequeApp/static/%s' % (ip) else: print "found" path1 = str(pathFix + "/chequeApp/static/" + ip + "/abc2.pdf") with open(path1, 'wb+') as destination: for chunk in f.chunks(): destination.write(chunk) print "path ", type(path1), type(path1), path1 img1 = PythonMagick.Image() imgDisplay = PythonMagick.Image() img1.density("300") imgDisplay.density("300") img1.read(path1) # read in at 300 dpi imgDisplay.read(path1) path1 = str(pathFix + "/chequeApp/static/" + ip + "/abc2.jpg") str1 = str(time.time()).replace('.', '') pathDisplay = str(pathFix + "/chequeApp/static/" + ip + "/abc%s.jpg" % (str1)) print type(path1), "----", type(pathDisplay), "*******", type(str1) img1.write(path1) imgDisplay.write(pathDisplay) img = PythonMagick.Image(path1) img.read(path1) # read in at 300 dpi imageSize = img.size() print "*******", imageSize.height(), "*****", imageSize.width() #img1 = Image.open(path1) #imgnew = img1.resize((854,1260)) #imgnew.save(path1) img.write(path1) return "abc%s.jpg" % (str1)