Fredrik Lundh is sharing code with you

Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.

Don't show this again

effbot / pil-2009-raclette http://effbot.org/zone/pil-index.htm

Work repository for PIL 1.1.7 and beyond. The "default" branch should be fairly solid, the other branches less so. For production use, see the pil-117 repository.

Clone this repository (size: 1.6 MB): HTTPS / SSH
hg clone https://bitbucket.org/effbot/pil-2009-raclette
hg clone ssh://hg@bitbucket.org/effbot/pil-2009-raclette

pil-2009-raclette / Tests / test_image_draft.py

from tester import *

from PIL import Image

filename = "Images/lena.jpg"

data = tostring(Image.open(filename).resize((512, 512)), "JPEG")

def draft(mode, size):
    im = fromstring(data)
    im.draft(mode, size)
    return im

def test_size():
    assert_equal(draft("RGB", (512, 512)).size, (512, 512))
    assert_equal(draft("RGB", (256, 256)).size, (256, 256))
    assert_equal(draft("RGB", (128, 128)).size, (128, 128))
    assert_equal(draft("RGB", (64, 64)).size, (64, 64))
    assert_equal(draft("RGB", (32, 32)).size, (64, 64))

def test_mode():
    assert_equal(draft("1", (512, 512)).mode, "RGB")
    assert_equal(draft("L", (512, 512)).mode, "L")
    assert_equal(draft("RGB", (512, 512)).mode, "RGB")
    assert_equal(draft("YCbCr", (512, 512)).mode, "YCbCr")