Drawing and Displaying an Image with PIL

W. eWatson notvalid2 at sbcglobal.net
Wed Jan 28 21:13:53 EST 2009


Peter Otten wrote:
> W. eWatson wrote:
> 
>> r wrote:
>>> Change this line:
>>> draw.line((0,0),(20,140), fill=128)
>>>
>>> To This:
>>> draw.line((0,0, 20,140), fill=128)
>>>
>>> And you should be good to go. Like you said, if you need to combine 2
>>> tuples you can do:
>>> (1,2)+(3,4)
>> Yes, that's true, but the big question is how to "see" the final image?
>> Either one employees another module or writes the file into a folder, then
>> displays it with a paint program?
> 
> For debugging purposes you can just invoke the show() method
> 
> im = Image.open(...)
> # modify image
> im.show() 
> 
> If you want to integrate the image into your own Tkinter program -- that is
> explained here:
> 
> http://effbot.org/tkinterbook/photoimage.htm
> 
> Following these instruction you code might become
> 
> import Tkinter as tk
> import Image
> import ImageTk
> import ImageDraw
> import sys
> 
> filename = sys.argv[1]
> im = Image.open(filename)
> 
> draw = ImageDraw.Draw(im)
> draw.line((0, 0) + im.size, fill=128)
> draw.line(((0,0),(20,140)), fill=128)
> 
> 
> root = tk.Tk()
> pi = ImageTk.PhotoImage(im)
> label = tk.Label(root, image=pi)
> label.pack()
> root.mainloop()
> 
> Peter
My initial quest was to do it in PIL. That seems impossible, and the way out 
is Tkinter. I'm not yet savvy enough with Pythons graphics. I was definitely 
leaning towards PhotoImage as the way out. What module is show in?

Repairing my (0,0), ... to (0,0)+, and. replacing arg with ImageOPen, 
produces a correct solution.

My NM Tech pdf misses the boat on PhotoImage. I've seen your reference 
before, but never looked at PhotoImage. I'll bookmark it. I sure wish it was 
in pdf format.

Thanks.


-- 
                                W. eWatson

              (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
               Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

                     Web Page: <www.speckledwithstars.net/>




More information about the Python-list mailing list