Re: [Tutor] Python Image Library
On 19/05/17 15:15, Peter Otten wrote: > call the destroy() rather than the quit() method. Nice! > > However, as your code gets away without calling destroy() I'm still > puzzled... withdraw hides the window then quit ends the mainloop so the procedure falls through to the end and everything gets garbage collected. Its brutal but it works. destroy combines the withdraw and quit effect in a much more elegant solution. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Image Library
Alan Gauld via Tutor wrote: > On 18/05/17 18:06, Alan Gauld via Tutor wrote: > >> Here is some untested Tkinter code to display an image >> for 2 seconds: > > I tried this last night and it turned out to be harder > than I expected. Eventually I got to bed at 3am! But here > is something that seems to work for jpegs. I hope bmp files > will too, I didn't have any to test... > > # > import tkinter as tk > from PIL import Image,ImageTk > > def showImage(imgName, delay=2000, wd=400, ht=400): >'''Display the file imgName > for delay milliseconds > in a window sized wd x ht > Close the window afterwards''' > >top = tk.Tk() >top.withdraw() # hide the root window >win = tk.Toplevel() >PILimage = Image.open(imgName) >TKimg = ImageTk.PhotoImage(PILimage) >tk.Label(win, image=TKimg, width=wd, height=ht).pack() >top.after(delay, lambda : (win.withdraw(), top.quit()) ) >top.mainloop() > > > ## Test code # > import glob,os > > root = r"/full/path/to/your/files" > > for filename in glob.glob(root + "/*.jpg"): > print(filename) > showImage(filename) I found your original sketch a bit more appealing and went to explore why it didn't work. The problem you already have fixed is passing a PhotoImage to the Label instead of the filename. The other seems to be that you need to call the destroy() rather than the quit() method. At least the following works on my Linux system, with jpegs: def show_image(imagename, delay=2000, width=None, height=None): root = tk.Tk() image = ImageTk.PhotoImage(Image.open(imagename)) tk.Label(root, image=image, width=width, height=height).pack() root.after(delay, root.destroy) root.mainloop() However, as your code gets away without calling destroy() I'm still puzzled... ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Image Library
On 19/05/17 10:29, Alan Gauld via Tutor wrote: > is something that seems to work for jpegs. I hope bmp files > will too, I didn't have any to test... I converted a few jpg to bmp. It does work but it turns out Pillow is quite fussy about the BMP format. I had to turn off colour space header info (in the GIMP export) to get them working. Others have had issues with unusual colour depths etc too. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Image Library
On 18/05/17 18:06, Alan Gauld via Tutor wrote: > Here is some untested Tkinter code to display an image > for 2 seconds: I tried this last night and it turned out to be harder than I expected. Eventually I got to bed at 3am! But here is something that seems to work for jpegs. I hope bmp files will too, I didn't have any to test... # import tkinter as tk from PIL import Image,ImageTk def showImage(imgName, delay=2000, wd=400, ht=400): '''Display the file imgName for delay milliseconds in a window sized wd x ht Close the window afterwards''' top = tk.Tk() top.withdraw() # hide the root window win = tk.Toplevel() PILimage = Image.open(imgName) TKimg = ImageTk.PhotoImage(PILimage) tk.Label(win, image=TKimg, width=wd, height=ht).pack() top.after(delay, lambda : (win.withdraw(), top.quit()) ) top.mainloop() ## Test code # import glob,os root = r"/full/path/to/your/files" for filename in glob.glob(root + "/*.jpg"): print(filename) showImage(filename) -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Image Library
I'll use it when I get to it! Thanks! For now, I use this, as suggested by eryk sun: os.startfile('1.bmp') it doesn't pop the window. Thanks Alan! On Thu, May 18, 2017 at 10:06 AM, Alan Gauld via Tutorwrote: > On 18/05/17 16:43, Michael C wrote: > > os.startfile('1.bmp') > > > > works like a charm! > > > > Now I need to figure out how to close this window once I finish with it! > > Sadly that is manual. Unless you care to write code to search for the > process and use the Windows API to kill it off. > > If you really want the image under your programs control you > need to build a GUI, even if a very basic one and display > the image in a window. A very simplistic Tkinter app will > do for simply splatting an image on screen then closing > it later. But it all depends what else you need the app to > do how complex it gets after that. > > Here is some untested Tkinter code to display an image > for 2 seconds: > > import tkinter as tk > > top = tk.Tk() > tk.Label(top, image='1.bmp').pack() > top.after(2000, top.quit) > > top.mainloop() > > If not that, something quite like it... > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.amazon.com/author/alan_gauld > Follow my photo-blog on Flickr at: > http://www.flickr.com/photos/alangauldphotos > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Image Library
On 18/05/17 16:43, Michael C wrote: > os.startfile('1.bmp') > > works like a charm! > > Now I need to figure out how to close this window once I finish with it! Sadly that is manual. Unless you care to write code to search for the process and use the Windows API to kill it off. If you really want the image under your programs control you need to build a GUI, even if a very basic one and display the image in a window. A very simplistic Tkinter app will do for simply splatting an image on screen then closing it later. But it all depends what else you need the app to do how complex it gets after that. Here is some untested Tkinter code to display an image for 2 seconds: import tkinter as tk top = tk.Tk() tk.Label(top, image='1.bmp').pack() top.after(2000, top.quit) top.mainloop() If not that, something quite like it... -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Image Library
os.startfile('1.bmp') works like a charm! Now I need to figure out how to close this window once I finish with it! On Thu, May 18, 2017 at 8:14 AM, Michael Cwrote: > Oh I have been using Pillow 4.0 the whole time alright, sorry I forgot to > mention it. > > On Thu, May 18, 2017 at 1:55 AM, Alan Gauld via Tutor > wrote: > >> On 18/05/17 02:58, Michael C wrote: >> > when I run this, while it's called test.pyw, this pops up >> > >> > from PIL import Image >> > >> > im = Image.open('1.bmp') >> > im.show() >> >> One suggestion is to use Pillow instead of PIL. >> So far as I know PIL is frozen and all new development >> is on Pillow. It is backwardly compatible although for >> this case that hardly matters! But it's just possible >> that this is fixed in Pillow? >> >> But if this is all you are using PIL for then its >> overkill and you would be much better off sing a >> different approach. But that depends on what you >> are trying to achieve. >> >> -- >> Alan G >> Author of the Learn to Program web site >> http://www.alan-g.me.uk/ >> http://www.amazon.com/author/alan_gauld >> Follow my photo-blog on Flickr at: >> http://www.flickr.com/photos/alangauldphotos >> >> >> ___ >> Tutor maillist - Tutor@python.org >> To unsubscribe or change subscription options: >> https://mail.python.org/mailman/listinfo/tutor >> > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Image Library
Did you go into the source code of PIL/Pillow? Awesome!!! On Wed, May 17, 2017 at 7:52 PM, eryk sunwrote: > On Thu, May 18, 2017 at 1:58 AM, Michael C > wrote: > > when I run this, while it's called test.pyw, this pops up > > > > from PIL import Image > > > > im = Image.open('1.bmp') > > im.show() > > Ok, I stand corrected. It's something weird, and most likely due to > Windows support here being an afterthought throw in just for coverage, > instead of something anyone actually cared about. The code does indeed > use os.system to show the file, which is just about the worst thing > one can do here for a Windows viewer. > > >>> print(inspect.getsource(ImageShow.WindowsViewer)) > class WindowsViewer(Viewer): > format = "BMP" > > def get_command(self, file, **options): > return ('start "Pillow" /WAIT "%s" ' > '&& ping -n 2 127.0.0.1 >NUL ' > '&& del /f "%s"' % (file, file)) > > >>> print(inspect.getsource(ImageShow.Viewer.show_file)) > def show_file(self, file, **options): > """Display given file""" > os.system(self.get_command(file, **options)) > return 1 > > The WindowsViewer class preferrably should override show_file to call > ShellExecuteExW directly via ctypes, and wait (if possible) to delete > the temporary file. Or at least use subprocess.call with shell=True, > which will hide the console window. Note that being able to wait on > the image viewer is not guaranteed. For example, the image viewer in > Windows 10 is an app that cannot be waited on. > > Since you already have a file on disk, you could skip PIL completely. > Just use os.startfile('1.bmp'). > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Image Library
Oh I have been using Pillow 4.0 the whole time alright, sorry I forgot to mention it. On Thu, May 18, 2017 at 1:55 AM, Alan Gauld via Tutorwrote: > On 18/05/17 02:58, Michael C wrote: > > when I run this, while it's called test.pyw, this pops up > > > > from PIL import Image > > > > im = Image.open('1.bmp') > > im.show() > > One suggestion is to use Pillow instead of PIL. > So far as I know PIL is frozen and all new development > is on Pillow. It is backwardly compatible although for > this case that hardly matters! But it's just possible > that this is fixed in Pillow? > > But if this is all you are using PIL for then its > overkill and you would be much better off sing a > different approach. But that depends on what you > are trying to achieve. > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.amazon.com/author/alan_gauld > Follow my photo-blog on Flickr at: > http://www.flickr.com/photos/alangauldphotos > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Image Library
On 18/05/17 02:58, Michael C wrote: > when I run this, while it's called test.pyw, this pops up > > from PIL import Image > > im = Image.open('1.bmp') > im.show() One suggestion is to use Pillow instead of PIL. So far as I know PIL is frozen and all new development is on Pillow. It is backwardly compatible although for this case that hardly matters! But it's just possible that this is fixed in Pillow? But if this is all you are using PIL for then its overkill and you would be much better off sing a different approach. But that depends on what you are trying to achieve. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Image Library
when I run this, while it's called test.pyw, this pops up from PIL import Image im = Image.open('1.bmp') im.show() [image: Inline image 1] On Wed, May 17, 2017 at 6:51 PM, eryk sunwrote: > On Wed, May 17, 2017 at 10:33 PM, Michael C > wrote: > > On Wed, May 17, 2017 at 3:30 PM, eryk sun wrote: > > > >> You're probably running a .py script that's associated with py.exe or > >> python.exe. These executables create a new console (i.e. an instance > >> of the console host process, conhost.exe), if they don't inherit one > >> from their parent process. The new console defaults to creating a > >> visible window. Change the file extension to .pyw. This file extension > >> should be associated with pyw.exe or pythonw.exe, which will not > >> create a console. > >> > >> FYI, the cmd shell is unrelated to that console window. Windows users > >> often confuse the cmd shell with the console window that it uses. I > >> suppose it's less confusing on Linux. Like cmd, bash will inherit the > >> parent's terminal/console; however, it doesn't automatically spawn a > >> terminal on Linux if the parent doesn't have one. (Getting that > >> behavior on Windows requires the DETACHED_PROCESS creation flag.) > >> Since Windows users typically run cmd.exe to get a command-line shell > >> for running programs, they associate cmd.exe with the console window. > >> It isn't obvious that other programs create consoles without any > >> associated instance of cmd.exe. > > > > Actually, that is the whole script! I didn't get used to have the cmd.exe > > window pop up at all, could it be something I did? > > Changing the script's extension to .pyw didn't prevent the console > from appearing? Or did you not try it? > > Also, to reiterate, the cmd shell doesn't create or own any window, > and unless something really weird is going on, there's no cmd.exe > instance associated with the console window that you're seeing. cmd > can use a console via standard I/O File handles, and usually does, but > not always. It's no different from python.exe, powershell.exe, or any > other console application. Really, there is no such thing as a "cmd > window", "python window", or "PowerShell window". Because these are > long-running shell processes (e.g. Python's REPL), people are inclined > to think in those terms, and that's fine, but would you call it a > "where.exe window", "chcp.com window", "doskey.exe window", > "whoami.exe window", "findstr.exe window"? I think not. It's clear > that these programs simply use the console; they don't own it. Neither > do shells, but in the case of shells and other long-running console > processes, we're loose with language for convenience -- as long as it > doesn't confuse our understanding of how things really work. > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Image Library
On Thu, May 18, 2017 at 1:58 AM, Michael Cwrote: > when I run this, while it's called test.pyw, this pops up > > from PIL import Image > > im = Image.open('1.bmp') > im.show() Ok, I stand corrected. It's something weird, and most likely due to Windows support here being an afterthought throw in just for coverage, instead of something anyone actually cared about. The code does indeed use os.system to show the file, which is just about the worst thing one can do here for a Windows viewer. >>> print(inspect.getsource(ImageShow.WindowsViewer)) class WindowsViewer(Viewer): format = "BMP" def get_command(self, file, **options): return ('start "Pillow" /WAIT "%s" ' '&& ping -n 2 127.0.0.1 >NUL ' '&& del /f "%s"' % (file, file)) >>> print(inspect.getsource(ImageShow.Viewer.show_file)) def show_file(self, file, **options): """Display given file""" os.system(self.get_command(file, **options)) return 1 The WindowsViewer class preferrably should override show_file to call ShellExecuteExW directly via ctypes, and wait (if possible) to delete the temporary file. Or at least use subprocess.call with shell=True, which will hide the console window. Note that being able to wait on the image viewer is not guaranteed. For example, the image viewer in Windows 10 is an app that cannot be waited on. Since you already have a file on disk, you could skip PIL completely. Just use os.startfile('1.bmp'). ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Image Library
On Wed, May 17, 2017 at 10:33 PM, Michael Cwrote: > On Wed, May 17, 2017 at 3:30 PM, eryk sun wrote: > >> You're probably running a .py script that's associated with py.exe or >> python.exe. These executables create a new console (i.e. an instance >> of the console host process, conhost.exe), if they don't inherit one >> from their parent process. The new console defaults to creating a >> visible window. Change the file extension to .pyw. This file extension >> should be associated with pyw.exe or pythonw.exe, which will not >> create a console. >> >> FYI, the cmd shell is unrelated to that console window. Windows users >> often confuse the cmd shell with the console window that it uses. I >> suppose it's less confusing on Linux. Like cmd, bash will inherit the >> parent's terminal/console; however, it doesn't automatically spawn a >> terminal on Linux if the parent doesn't have one. (Getting that >> behavior on Windows requires the DETACHED_PROCESS creation flag.) >> Since Windows users typically run cmd.exe to get a command-line shell >> for running programs, they associate cmd.exe with the console window. >> It isn't obvious that other programs create consoles without any >> associated instance of cmd.exe. > > Actually, that is the whole script! I didn't get used to have the cmd.exe > window pop up at all, could it be something I did? Changing the script's extension to .pyw didn't prevent the console from appearing? Or did you not try it? Also, to reiterate, the cmd shell doesn't create or own any window, and unless something really weird is going on, there's no cmd.exe instance associated with the console window that you're seeing. cmd can use a console via standard I/O File handles, and usually does, but not always. It's no different from python.exe, powershell.exe, or any other console application. Really, there is no such thing as a "cmd window", "python window", or "PowerShell window". Because these are long-running shell processes (e.g. Python's REPL), people are inclined to think in those terms, and that's fine, but would you call it a "where.exe window", "chcp.com window", "doskey.exe window", "whoami.exe window", "findstr.exe window"? I think not. It's clear that these programs simply use the console; they don't own it. Neither do shells, but in the case of shells and other long-running console processes, we're loose with language for convenience -- as long as it doesn't confuse our understanding of how things really work. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Image Library
Actually, that is the whole script! I didn't get used to have the cmd.exe window pop up at all, could it be something I did? Or, is there a way to suppress that from showing up? thanks! On Wed, May 17, 2017 at 3:30 PM, eryk sunwrote: > On Wed, May 17, 2017 at 8:24 PM, Michael C > wrote: > > from PIL import Image > > > > im = Image.open('pic.bmp') > > im.show() > > > > I ran this code and it not only opened the picture in paint, which is > what > > I want, but it also opens a CMD.exe console window! how do I prevent > that from > > happening? > > You're probably running a .py script that's associated with py.exe or > python.exe. These executables create a new console (i.e. an instance > of the console host process, conhost.exe), if they don't inherit one > from their parent process. The new console defaults to creating a > visible window. Change the file extension to .pyw. This file extension > should be associated with pyw.exe or pythonw.exe, which will not > create a console. > > FYI, the cmd shell is unrelated to that console window. Windows users > often confuse the cmd shell with the console window that it uses. I > suppose it's less confusing on Linux. Like cmd, bash will inherit the > parent's terminal/console; however, it doesn't automatically spawn a > terminal on Linux if the parent doesn't have one. (Getting that > behavior on Windows requires the DETACHED_PROCESS creation flag.) > Since Windows users typically run cmd.exe to get a command-line shell > for running programs, they associate cmd.exe with the console window. > It isn't obvious that other programs create consoles without any > associated instance of cmd.exe. > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Image Library
On Wed, May 17, 2017 at 8:24 PM, Michael Cwrote: > from PIL import Image > > im = Image.open('pic.bmp') > im.show() > > I ran this code and it not only opened the picture in paint, which is what > I want, but it also opens a CMD.exe console window! how do I prevent that from > happening? You're probably running a .py script that's associated with py.exe or python.exe. These executables create a new console (i.e. an instance of the console host process, conhost.exe), if they don't inherit one from their parent process. The new console defaults to creating a visible window. Change the file extension to .pyw. This file extension should be associated with pyw.exe or pythonw.exe, which will not create a console. FYI, the cmd shell is unrelated to that console window. Windows users often confuse the cmd shell with the console window that it uses. I suppose it's less confusing on Linux. Like cmd, bash will inherit the parent's terminal/console; however, it doesn't automatically spawn a terminal on Linux if the parent doesn't have one. (Getting that behavior on Windows requires the DETACHED_PROCESS creation flag.) Since Windows users typically run cmd.exe to get a command-line shell for running programs, they associate cmd.exe with the console window. It isn't obvious that other programs create consoles without any associated instance of cmd.exe. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Image Library
in fact, when I ran this: import os os.system("mspaint 1.bmp") It also opened a cmd.exe window and the script wouldn't continue until I closed the cmd window! On Wed, May 17, 2017 at 1:24 PM, Michael Cwrote: > from PIL import Image > > > im = Image.open('pic.bmp') > im.show() > > > I ran this code and it not only opened the picture in paint, which is what > I want, > but it also opens a CMD.exe console window! how do I prevent that from > happening? > > thanks! > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Image library
You know the height and the width of the image, no? So you know that every 'width' number of pixels will start a new row. So if you wanted say the fifth row down, second pixel, how would you find it? The 1st line: 'width' number of pixels The 2nd line: 'width' number of pixels The 3rd line: 'width number of pixels The 4th line: 'width' number of pixels The 5th line: 2 pixels in from the left Add those up ~ width+width+width+width+2 Or 4*width+2 That number is the index to use to get the pixel at coords (2,5) so pixel = getdata() pixel[4*width+2] For this example. Work out a more general solution for yourself please. JS getdata() returns a flattened list, [n] but i am not sure how to access it. when I want to get rgb from a window of 100,200, get data starts from 0(0~99, 0~199) the point of x,y = 2, 1 do I put in pixel[100] ? it's actually not the case @_@ what should I put in ? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Image library
ahh~ it goes horizontally first why didn't I think of that? thank you ~ On 7/19/07, Tiger12506 [EMAIL PROTECTED] wrote: You know the height and the width of the image, no? So you know that every 'width' number of pixels will start a new row. So if you wanted say the fifth row down, second pixel, how would you find it? The 1st line: 'width' number of pixels The 2nd line: 'width' number of pixels The 3rd line: 'width number of pixels The 4th line: 'width' number of pixels The 5th line: 2 pixels in from the left Add those up ~ width+width+width+width+2 Or 4*width+2 That number is the index to use to get the pixel at coords (2,5) so pixel = getdata() pixel[4*width+2] For this example. Work out a more general solution for yourself please. JS getdata() returns a flattened list, [n] but i am not sure how to access it. when I want to get rgb from a window of 100,200, get data starts from 0(0~99, 0~199) the point of x,y = 2, 1 do I put in pixel[100] ? it's actually not the case @_@ what should I put in ? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Image library
Tiger12506 wrote: You know the height and the width of the image, no? So you know that every 'width' number of pixels will start a new row. So if you wanted say the fifth row down, second pixel, how would you find it? The 1st line: 'width' number of pixels The 2nd line: 'width' number of pixels The 3rd line: 'width number of pixels The 4th line: 'width' number of pixels The 5th line: 2 pixels in from the left Add those up ~ width+width+width+width+2 Or 4*width+2 if you start counting at the 0th row and 0th column, this will give you the 4th row and 2nd column. if you're counting from the 1st row and 1st column, this will give you the 5th row and 3rd column. That number is the index to use to get the pixel at coords (2,5) So this is actually (3,5) or, to count from 0, (2,4). But yeah, the general idea is there. If my math is wrong I'm sure you won't hesitate to correct me ;) -Luke ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Image library
that's illustrative. On 7/19/07, Luke Paireepinart [EMAIL PROTECTED] wrote: Tiger12506 wrote: You know the height and the width of the image, no? So you know that every 'width' number of pixels will start a new row. So if you wanted say the fifth row down, second pixel, how would you find it? The 1st line: 'width' number of pixels The 2nd line: 'width' number of pixels The 3rd line: 'width number of pixels The 4th line: 'width' number of pixels The 5th line: 2 pixels in from the left Add those up ~ width+width+width+width+2 Or 4*width+2 if you start counting at the 0th row and 0th column, this will give you the 4th row and 2nd column. if you're counting from the 1st row and 1st column, this will give you the 5th row and 3rd column. That number is the index to use to get the pixel at coords (2,5) So this is actually (3,5) or, to count from 0, (2,4). But yeah, the general idea is there. If my math is wrong I'm sure you won't hesitate to correct me ;) -Luke ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python Image library
if you start counting at the 0th row and 0th column, this will give you the 4th row and 2nd column. if you're counting from the 1st row and 1st column, this will give you the 5th row and 3rd column. That number is the index to use to get the pixel at coords (2,5) So this is actually (3,5) or, to count from 0, (2,4). But yeah, the general idea is there. If my math is wrong I'm sure you won't hesitate to correct me ;) -Luke No. You're right, of course. :-) I wasn't thinking. JS ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor