Exemplo n.º 1
0
        adjust_image(f, max_size=conf['MAX_SIZE'], new_format=conf['FORMAT'],
                     jpeg_quality=conf['JPEG_QUALITY'], fill=conf['FILL'], stretch=conf['STRETCH'])
        img_id = generate_img_id(profile, ext=image_get_format(f),
                                 label=request.POST.get('label'), tmp=True)
        relative_path = get_relative_path_from_img_id(img_id)
        full_path = media_path(relative_path)
        save_file(f, full_path)
        data = {
            'url': settings.MEDIA_URL + relative_path,
            'rel_url': relative_path,
            'img_id': img_id,
            'variants': {},
        }
        for v_conf in conf['VARIANTS']:
            label = v_conf['LABEL']
            if not label:
                label = get_variant_label(v_conf)
            v_f = adjust_image(f, max_size=v_conf['MAX_SIZE'], new_format=v_conf['FORMAT'],
                               jpeg_quality=v_conf['JPEG_QUALITY'], fill=v_conf['FILL'],
                               stretch=v_conf['STRETCH'], return_new_image=True)
            v_relative_path = get_relative_path_from_img_id(img_id, variant_label=label,
                                                            ext=image_get_format(v_f))
            v_full_path = media_path(v_relative_path)
            save_file(v_f, v_full_path)
            data['variants'][label] = {
                'url': settings.MEDIA_URL + v_relative_path,
                'rel_url': v_relative_path,
            }
        result['uploaded'].append(data)
    return send_json(result)
Exemplo n.º 2
0
         f,
         max_size=conf["MAX_SIZE"],
         new_format=conf["FORMAT"],
         jpeg_quality=conf["JPEG_QUALITY"],
         fill=conf["FILL"],
         stretch=conf["STRETCH"],
     )
     img_id = generate_img_id(profile, ext=image_get_format(f), label=request.POST.get("label"), tmp=True)
     relative_path = get_relative_path_from_img_id(img_id)
     full_path = media_path(relative_path)
     save_file(f, full_path)
     data = {"url": settings.MEDIA_URL + relative_path, "rel_url": relative_path, "img_id": img_id, "variants": {}}
     for v_conf in conf["VARIANTS"]:
         label = v_conf["LABEL"]
         if not label:
             label = get_variant_label(v_conf)
         v_f = adjust_image(
             f,
             max_size=v_conf["MAX_SIZE"],
             new_format=v_conf["FORMAT"],
             jpeg_quality=v_conf["JPEG_QUALITY"],
             fill=v_conf["FILL"],
             stretch=v_conf["STRETCH"],
             return_new_image=True,
         )
         v_relative_path = get_relative_path_from_img_id(img_id, variant_label=label, ext=image_get_format(v_f))
         v_full_path = media_path(v_relative_path)
         save_file(v_f, v_full_path)
         data["variants"][label] = {"url": settings.MEDIA_URL + v_relative_path, "rel_url": v_relative_path}
     result["uploaded"].append(data)
 return send_json(result)
Exemplo n.º 3
0
 def test_get_variant_label(self):
     self.assertEqual(get_variant_label({'MAX_SIZE': (10, 20)}), '10x20')
     self.assertEqual(get_variant_label({'MAX_SIZE': (10, None)}), 'w10')
     self.assertEqual(get_variant_label({'MAX_SIZE': (None, 20)}), 'h20')
Exemplo n.º 4
0
 def test_get_variant_label(self):
     self.assertEqual(get_variant_label({'MAX_SIZE': (10, 20)}), '10x20')
     self.assertEqual(get_variant_label({'MAX_SIZE': (10, None)}), 'w10')
     self.assertEqual(get_variant_label({'MAX_SIZE': (None, 20)}), 'h20')