Exemplo n.º 1
0
    def test_delete(self):
        image = Image()
        image.filename.save('1.jpg', FILES[0])
        filepath = image.filename.path
        image.delete()

        if os.path.exists(filepath):
            self.fail("Associated file was not deleted after instance deletion.")
Exemplo n.º 2
0
    def test_image_creation(self):
        image = Image()
        image.filename.save('1.jpg', FILES[0])

        if not os.path.exists(image.filename.path):
            self.fail("Image file was saved properly.")

        self.assertEqual(image.title, '1')

        image.delete()
Exemplo n.º 3
0
def color_bg(request, color, opacity=100):
    """
    Generates a 10x10 square image in the color requested.
    Useful for generating background colors based on user-provided 
    color settings.
    """
    import Image, ImageDraw, ImageColor

    alpha = int((int(opacity) / 100.0) * 255)

    if len(color) != 3 and len(color) != 6:
        raise Http404
    color = "#%s" % color
    color = ImageColor.getrgb(color) + (alpha,)

    size = (10, 10)

    etag = md5_constructor("%s%s" % (color, size)).hexdigest()
    if request.META.get("HTTP_IF_NONE_MATCH") == etag:
        return HttpResponseNotModified()

    img = Image.new("RGBA", size=size, color=color)

    response = HttpResponse(mimetype="image/png")
    img.save(response, "PNG")
    response["Etag"] = etag
    return response