Python-list Digest, Vol 64, Issue 617

Ferdinand Sousa ferdinandsousa at gmail.com
Wed Jan 28 03:40:13 EST 2009


>
> Secondly, it has no way to display the image drawn on. Is it possible, or
>>> do
>>> I have to pass the image off to another module's methods?
>>
>> im.show() this will display the image (and any modification(s) made to
it)

>
>> Example: Draw a Grey Cross Over an Image
>> import Image, ImageDraw
>> im = Image.open("lena.pgm")
>> draw = ImageDraw.Draw(im)
>> draw.line((0, 0) + im.size, fill=128)
>> draw.line((0, im.size[1], im.size[0], 0), fill=128)
>> del draw
>> # write to stdout
>> im.save(sys.stdout, "PNG")
>>
>> Hope that helps
>>
> That's pretty much the code I used. In fact, I borrowed it from the pdf. I
> just tried it, and it output "%PNG".
>
> im.save("picture1.png")
OR
im.save("picture1" "png") # not sure if it has to be "PNG"

What was happening earlier was that the binary data was being directed to
the standard output, which is where all your text is printed by a print
statement (print func in Py 3000). If you open a png in notepad, you will
notice that the 1st four characters are indeed %PNG, which is the magic
number for a PNG file.
For further info, see:
http://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_files<http://en.wikipedia.org/wiki/Magic_number_%28programming%29#Magic_numbers_in_files>
http://en.wikipedia.org/wiki/Portable_Network_Graphics#File_header

Regards,
Ferdi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090128/d36c0635/attachment.html>


More information about the Python-list mailing list