new images from strings using PIL
Fredrik Lundh
fredrik at pythonware.com
Sun Mar 3 17:32:21 EST 2002
"BL" <metaliu at yahoo.com> wrote:
> pixels = "1 2 3 4 5 6" //test pixels
> im = Image.fromstring("I", (2,1), pixels) //create a 3x2 image from pixels
try this instead:
>>> pixels = "1 2 3 4 5 6"
>>> i = Image.new("L", (3, 2))
>>> i.putdata(map(int, pixels.split()))
>>> list(i.getdata())
[1, 2, 3, 4, 5, 6]
>>> i.getextrema()
(1, 6)
(getdata returns a sequence object of an undefined type. to
see what's in it, convert it to a list or tuple before printing it)
</F>
More information about the Python-list
mailing list