Exemple #1
0
def saveImage(request, data):
    randomStr = stringutil.genRandomString(10)
    fileNameServer = randomStr + '.jpg'
    destinationFile = settings.UPLOAD_FOLDER + '/' + fileNameServer
    imgPIL = imconvert.binary_2_PIL(data)
    if 'canvas-size[width]' in request.GET.keys() and 'canvas-size[height]' in request.GET.keys():
        canvasWidth = int(request.GET['canvas-size[width]'])
        canvasHeight = int(request.GET['canvas-size[height]'])
        imtransform.scalePILImage(imgPIL, (canvasWidth, canvasHeight))
    if 'canvas-size[width]' in request.POST.keys() and 'canvas-size[height]' in request.POST.keys():
        canvasWidth = int(request.POST['canvas-size[width]'])
        canvasHeight = int(request.POST['canvas-size[height]'])
        imtransform.scalePILImage(imgPIL, (canvasWidth, canvasHeight))
    imgPIL.save(destinationFile, "JPEG")
    request.session['original_image'] = fileNameServer
    return JsonResponse({'imgUrl': settings.UPLOAD_URL + "/" + fileNameServer})
Exemple #2
0
def saveImage(request, data):
    randomStr = stringutil.genRandomString(10)
    fileNameServer = randomStr + '.jpg'
    destinationFile = settings.UPLOAD_FOLDER + '/' + fileNameServer
    imgPIL = imconvert.binary_2_PIL(data)
    if 'canvas-size[width]' in request.GET.keys(
    ) and 'canvas-size[height]' in request.GET.keys():
        canvasWidth = int(request.GET['canvas-size[width]'])
        canvasHeight = int(request.GET['canvas-size[height]'])
        imtransform.scalePILImage(imgPIL, (canvasWidth, canvasHeight))
    if 'canvas-size[width]' in request.POST.keys(
    ) and 'canvas-size[height]' in request.POST.keys():
        canvasWidth = int(request.POST['canvas-size[width]'])
        canvasHeight = int(request.POST['canvas-size[height]'])
        imtransform.scalePILImage(imgPIL, (canvasWidth, canvasHeight))
    imgPIL.save(destinationFile, "JPEG")
    request.session['original_image'] = fileNameServer
    return JsonResponse({'imgUrl': settings.UPLOAD_URL + "/" + fileNameServer})
Exemple #3
0
def receivePILImage(request, label):
    if request.method != 'POST':
        return None
    if label in request.POST:
        imgData64 = request.POST[label]
        if imgData64 is not None and len(imgData64) > 0:
            im = imconvert.base64_2_PIL(imgData64)
    elif label in request.FILES:
        file = request.FILES[label]
        if file is not None:
            imgData = file.read()
            if imgData is not None and len(imgData) > 0:
                im = imconvert.binary_2_PIL(imgData)
    else:
        return None
    if im is not None and im.mode == "RGBA": # canvas image is sent with an alpha layer
        # Create a new image with a solid color
        background = Image.new('RGBA', im.size, (255, 255, 255))
        # Paste the image on top of the background
        background.paste(im, im)
        im = background.convert('RGB')
        return im
    return None
Exemple #4
0
def receivePILImage(request, label):
    if request.method != 'POST':
        return None
    if label in request.POST:
        imgData64 = request.POST[label]
        if imgData64 is not None and len(imgData64) > 0:
            im = imconvert.base64_2_PIL(imgData64)
    elif label in request.FILES:
        file = request.FILES[label]
        if file is not None:
            imgData = file.read()
            if imgData is not None and len(imgData) > 0:
                im = imconvert.binary_2_PIL(imgData)
    else:
        return None
    if im is not None and im.mode == "RGBA":  # canvas image is sent with an alpha layer
        # Create a new image with a solid color
        background = Image.new('RGBA', im.size, (255, 255, 255))
        # Paste the image on top of the background
        background.paste(im, im)
        im = background.convert('RGB')
        return im
    return None