Ejemplo n.º 1
0
    def save(self, commit=True):
        img = scale_and_crop(self.files['image'], **MARKDOWNX_IMAGE_MAX_SIZE)
        thumb_io = BytesIO()
        img.save(thumb_io,
                 self.files['image'].content_type.split('/')[-1].upper())

        file_name = str(self.files['image'])
        thumb_io.seek(0, os.SEEK_END)
        img = InMemoryUploadedFile(thumb_io, "image", file_name,
                                   self.files['image'].content_type,
                                   thumb_io.tell(), None)

        unique_file_name = self.get_unique_file_name(file_name)
        full_path = os.path.join(settings.MEDIA_ROOT, MARKDOWNX_MEDIA_PATH,
                                 unique_file_name)
        if not os.path.exists(os.path.dirname(full_path)):
            os.makedirs(os.path.dirname(full_path))

        destination = open(full_path, 'wb+')
        for chunk in img.chunks():
            destination.write(chunk)
        destination.close()

        return os.path.join(settings.MEDIA_URL, MARKDOWNX_MEDIA_PATH,
                            unique_file_name)
Ejemplo n.º 2
0
def build_xlsx_response(wb, title="report"):
    title = generate_filename(title, '.xlsx')
    myfile = BytesIO()
    myfile.write(save_virtual_workbook(wb))
    response = HttpResponse(
        myfile.getvalue(),
        content_type=
        'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
    response['Content-Disposition'] = 'attachment; filename=%s' % title
    response['Content-Length'] = myfile.tell()
    return response
Ejemplo n.º 3
0
def yeter(request, type):
    form = PhotoForm(data=request.POST, files=request.FILES)
    if form.is_valid():
        img_data = dict(request.POST.items())
        x = None  # Coordinate x
        y = None  # Coordinate y
        w = None  # Width
        h = None  # Height
        rotate = None  # Rotate
        for key, value in img_data.items():
            if key == "avatar_data":
                str_value = json.loads(value)
                print(str_value)
                x = str_value.get('x')
                y = str_value.get('y')
                w = str_value.get('width')
                h = str_value.get('height')
                rotate = str_value.get('rotate')

        print('x: {}, y: {}, w: {}, h: {}, rotate: {}'.format(
            x, y, w, h, rotate))

        im = Image.open(request.FILES['file']).convert('RGBA')
        tempfile = im.rotate(-rotate, expand=True)
        tempfile = tempfile.crop((int(x), int(y), int(w + x), int(h + y)))
        tempfile_io = BytesIO()
        tempfile_io.seek(0, os.SEEK_END)
        tempfile.save(tempfile_io, format='PNG')
        image_file = InMemoryUploadedFile(tempfile_io, None,
                                          'rotate.png', 'image/png',
                                          tempfile_io.tell(), None)
        image_file = compressImage(image_file)
        if type == "profile":
            Photo.objects.filter(user=request.user).delete()
            Photo.objects.create(user=request.user, file=image_file)
        elif type == "cover":
            CoverPhoto.objects.filter(user=request.user).delete()
            CoverPhoto.objects.create(user=request.user, file=image_file)

        data = {
            'result': True,
            'state': 200,
            'message': 'Yükleme Başarılı',
        }
        return JsonResponse({'data': data})
    else:
        print('Uncut image!')
        print(form.errors)

    return redirect('user:profile', request.user)
Ejemplo n.º 4
0
    def save(self, commit=True):
        img = scale_and_crop(self.files['image'], **MARKDOWNX_IMAGE_MAX_SIZE)
        thumb_io = BytesIO()
        img.save(thumb_io,
                 self.files['image'].content_type.split('/')[-1].upper())

        file_name = str(self.files['image'])
        thumb_io.seek(0, os.SEEK_END)
        img = InMemoryUploadedFile(thumb_io, None, file_name,
                                   self.files['image'].content_type,
                                   thumb_io.tell(), None)

        unique_file_name = self.get_unique_file_name(file_name)
        full_path = os.path.join(MARKDOWNX_MEDIA_PATH, unique_file_name)
        default_storage.save(full_path, img)

        return default_storage.url(full_path)
Ejemplo n.º 5
0
    def save(self, commit=True):
        img = scale_and_crop(self.files['image'], **MARKDOWNX_IMAGE_MAX_SIZE)
        thumb_io = BytesIO()
        img.save(thumb_io, self.files['image'].content_type.split('/')[-1].upper())

        file_name = str(self.files['image'])
        thumb_io.seek(0, os.SEEK_END)
        img = InMemoryUploadedFile(thumb_io, None, file_name, self.files['image'].content_type, thumb_io.tell(), None)

        unique_file_name = self.get_unique_file_name(file_name)
        full_path = os.path.join(MARKDOWNX_MEDIA_PATH, unique_file_name)
        default_storage.save(full_path, img)

        return default_storage.url(full_path)
Ejemplo n.º 6
0
    def save(self, commit=True):
        img = scale_and_crop(self.files['image'], **MARKDOWNX_IMAGE_MAX_SIZE)
        thumb_io = BytesIO()
        img.save(thumb_io,  self.files['image'].content_type.split('/')[-1].upper())

        file_name = str(self.files['image'])
        thumb_io.seek(0, os.SEEK_END)
        img = InMemoryUploadedFile(thumb_io, "image", file_name, self.files['image'].content_type, thumb_io.tell(), None)

        unique_file_name = self.get_unique_file_name(file_name)
        full_path = os.path.join(settings.MEDIA_ROOT, MARKDOWNX_MEDIA_PATH, unique_file_name)
        if not os.path.exists(os.path.dirname(full_path)):
            os.makedirs(os.path.dirname(full_path))

        destination = open(full_path, 'wb+')
        for chunk in img.chunks():
            destination.write(chunk)
        destination.close()

        return os.path.join(settings.MEDIA_URL, MARKDOWNX_MEDIA_PATH, unique_file_name)