예제 #1
0
    def test_resize_no_crop(self):
        image = Mock()
        image.crop.return_value = image
        image.size = (10, 10)

        target = (20, 20)
        crop_resize(image, target)

        assert image.crop.called is False
        image.resize.assert_called_with(target, Image.ANTIALIAS)
예제 #2
0
    def test_resize_horizontal_crop(self):
        image = Mock()
        image.crop.return_value = image
        image.size = (10, 10)

        target = (10, 5)
        crop_resize(image, target)

        assert image.crop.called is True
        image.crop.assert_called_with((0, 2, 10, 8))
        image.resize.assert_called_with(target, Image.ANTIALIAS)
예제 #3
0
    def test_resize_vertical_crop(self):
        image = Mock()
        image.crop.return_value = image
        image.size = (10, 10)

        target = (5, 10)
        crop_resize(image, target)

        assert image.crop.called is True
        image.crop.assert_called_with((2, 0, 8, 10))
        image.resize.assert_called_with(target, Image.ANTIALIAS)
예제 #4
0
def placeholder_image(w, h, ext='jpeg'):
    # Check max dimensions
    maxh = current_app.config['MAX_IMAGE_HEIGHT']
    maxw = current_app.config['MAX_IMAGE_WIDTH']
    if h > maxh or w > maxw:
        raise BadRequest('Image must be smaller than %ix%i' % (maxw, maxh))

    if ext not in ALLOWED_IMAGE_FORMATS:
        raise BadRequest(
            'Allowed formats are: %s' % ', '.join(ALLOWED_IMAGE_FORMATS)
        )

    img = random.choice(images)
    img = crop_resize(img, (w, h))
    return serve_pil_image(img, ext)