From jonathan.gilligan@vanderbilt.edu Tue Aug 1 16:32:38 2000 From: jonathan.gilligan@vanderbilt.edu (Jonathan M. Gilligan) Date: Tue, 01 Aug 2000 10:32:38 -0500 Subject: [Image-SIG] PIL and wxPython? Message-ID: <4.3.2.7.2.20000801103034.05285760@g.mail.vanderbilt.edu> Does anyone know if it's possible to display a PIL image in wxPython? Is it possible to convert a PIL image into a wxImage or a wxBitmap? I am now using VTK for image processing with wxPython and would like to switch to PIL/Numeric, which is more efficient for my purposes. Thanks, Jonathan =========================================================================== Jonathan M. Gilligan Research Assistant Professor of Physics (615) 343-6252 Dept. of Physics and Astronomy, Box 1807-B Fax: 343-7263 6823 Stevenson Center Vanderbilt University, Nashville, TN 37235 Dep't Office: 322-2828 From jhauser@ifm.uni-kiel.de Tue Aug 1 17:21:51 2000 From: jhauser@ifm.uni-kiel.de (Janko Hauser) Date: Tue, 1 Aug 2000 18:21:51 +0200 (CEST) Subject: [Image-SIG] PIL and wxPython? In-Reply-To: <4.3.2.7.2.20000801103034.05285760@g.mail.vanderbilt.edu> References: <4.3.2.7.2.20000801103034.05285760@g.mail.vanderbilt.edu> Message-ID: <20000801162151.11142.qmail@lisboa.ifm.uni-kiel.de> Yes it is quite easy if you use the wxpython backend of piddle, which is probably quite useful for imagegeneration in wxpython. Here is the baseclass: class SWXCanvasImage(PiddleWXCanvas): def __init__(self, parent, data): PiddleWXCanvas.__init__(self, parent) self.dataimage = swxm.ArrayToImage(data) def DoDrawing(self,dc): pdc = PiddleWxDc(dc) pdc.drawImage(self.dataimage,0,0) and swxm.ArrayToImage(data) is the following function: # file swxm.py # import Numeric import Image def normalize(a): a = Numeric.array(a, copy=1) a = (a - Numeric.minimum.reduce(a.flat))/(Numeric.maximum.reduce(a.flat) \ - Numeric.minimum.reduce(a.flat)) return ( a*254 ).astype('b') def ArrayToImage(a, height=200, scale=1): a = normalize(a) i = Image.new("L", (a.shape[1], a.shape[0]), color=255) i.fromstring(a.tostring()) if scale != 1: i = i.resize((i.size[0]*scale, i.size[1]*scale)) return i def ImageToArray(i): a = fromstring(i.tostring(), 'b') a.shape = i.im.size[1], i.im.size[0] return a HTH, __Janko -- Institut fuer Meereskunde phone: 49-431-597 3989 Dept. Theoretical Oceanography fax : 49-431-565876 Duesternbrooker Weg 20 email: jhauser@ifm.uni-kiel.de 24105 Kiel, Germany From bowern@ses.curtin.edu.au Tue Aug 1 17:53:19 2000 From: bowern@ses.curtin.edu.au (Nick Bower) Date: Tue, 01 Aug 2000 16:53:19 GMT Subject: [Image-SIG] bunch of pil errors Message-ID: <20000801.16531900@cricket.> On a Mandrake 7.1 system, piddle wouldn't work with the PIL package=20 (1.0b) already installed: File "/usr/lib/python1.5/site-packages/PIL/ImageTk.py", line 113, in=20 paste self.__photo.tk.call("PyImagingPhoto", self.__photo, block.id) TclError: invalid command name "PyImagingPhoto" So maybe upgrading to 1.1 will fix the problem. But it won't compile: tar zxvf Imaging-1.1...tgz cd Imaging-1.1/libImage ./configure make cd .. make -f Makefile.pre.in boot And here's what it spits: rm -f *.o *~ rm -f *.a tags TAGS config.c Makefile.pre python sedscript rm -f *.so *.sl so_locations VERSION=3D`python -c "import sys; print sys.version[:3]"`; \ installdir=3D`python -c "import sys; print sys.prefix"`; \ exec_installdir=3D`python -c "import sys; print sys.exec_prefix"`; \ make -f ./Makefile.pre.in VPATH=3D. srcdir=3D. \ VERSION=3D$VERSION \ installdir=3D$installdir \ exec_installdir=3D$exec_installdir \ Makefile make[1]: Entering directory `/home/nickb/Imaging-1.1' make[1]: *** No rule to make target `/usr/lib/python1.5/config/Makefile'= ,=20 needed by `sedscript'. Stop. make[1]: Leaving directory `/home/nickb/Imaging-1.1' make: *** [boot] Error 2 Call me a dummy, but I have no clue what this is saying. nick From kuncej@mail.conservation.state.mo.us Wed Aug 2 22:54:31 2000 From: kuncej@mail.conservation.state.mo.us (Jeffrey Kunce) Date: Wed, 02 Aug 2000 16:54:31 -0500 Subject: [Image-SIG] PIL and wxPython? Message-ID: >Does anyone know if it's possible to display a PIL image in wxPython? Is = it=20 >possible to convert a PIL image into a wxImage or a wxBitmap? I have an application called "Image Squeezer" that does batch resize=20 and compression of image files. It uses both PIL and wxPython. The=20 basic program was very simple (took half a day to write). Unfortunately, it caught a case of "feature-itis" and got a little bloated. But you = should be able to dig out plenty of tidbits for PIL/wxPython integration. Available at: http://starship.python.net/crew/jjkunce/=20 --Jeff From bowern@ses.curtin.edu.au Thu Aug 3 03:31:23 2000 From: bowern@ses.curtin.edu.au (Nick Bower) Date: Thu, 03 Aug 2000 02:31:23 GMT Subject: [Image-SIG] Palette documentation? Message-ID: <20000803.2312300@cricket.> Hi - I've been trying to work out how to use a custom palette with PIL=20 with no success. I have a 4-byte (indexed) input image (output from a plotting package=20 actually) in which each index is distinctly different: 0=3Dback,=20 1=3Dred,...16=3Dwhite. To view this I am creating a PIL PhotoImage and = then=20 embed this into a Tk Canvas. Unfortunately I can't find any documented way on the ImagePalette format= =20 so I can create a new one to match my input image. The linear ramping o= f=20 RGB mode is obviously inappropriate and results in no color separation. Can someone help me? Thanks very much, Nick, From bowern@ses.curtin.edu.au Thu Aug 3 05:31:42 2000 From: bowern@ses.curtin.edu.au (Nick Bower) Date: Thu, 03 Aug 2000 04:31:42 GMT Subject: [Image-SIG] ImageTk bug Message-ID: <20000803.4314200@cricket.> --------------=_4D4800BBE4640871F1F0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I think I've figured out how to use the palette, but I may have found a = bug in the PhotoImage class of ImageTk. If the marked line in the short= =20 testcode (attached) isn't commented out, the program segfaults as you'll= =20 see by running it. Anyone know how else to make palettes work with Tk? nick --------------=_4D4800BBE4640871F1F0 Content-Description: filename="piltest.py" Content-Disposition: inline; filename="piltest.py" Content-Type: text/plain; name ="piltest.py" Content-Transfer-Encoding: quoted-printable #!/usr/bin/python from Tkinter import * import Image, ImageTk class piltest(Frame): def __init__(self, toplevel): # GUI Setup Frame.__init__(self,toplevel) self.photoimage =3D ImageTk.PhotoImage('P',(300,300)) imagecanvas =3D Canvas(self, width=3D300,height=3D300) imagecanvas.pack(side=3DBOTTOM) imagecanvas.create_image(150,150,image=3Dself.photoimage) def putdata(self,data): im =3D Image.new('P', (300,300)) im.putdata(data) palette =3D [0] * 3 * 256 palette[0 :14 ] =3D [0, 0, 0, 200,0, 255,0, 187,127,219,1= 12,163,171,230,127] palette[0+256:14+256] =3D [0, 0, 0, 200,0, 255,0, 187,127,219,1= 12,163,171,230,127] palette[0+512:14+512] =3D [0, 0, 255,0, 255,255,115,0, 127,147,2= 19,255,127,0, 127] # # IF THE FOLLOWING LINE IS UNCOMMENTED, A SEGAULT OCCURS AFTER # THE PHOTOIMAGE PASTE METHOD # im.putpalette(palette) print 'trying to paste' self.photoimage.paste(im) print 'done pasting - no more code' # Run as script if (__name__ =3D=3D '__main__'): toplevel =3D Tk() atest =3D piltest(toplevel) atest.pack() atest.putdata([0,1]*45000) # simulate 300x300 image atest.mainloop() --------------=_4D4800BBE4640871F1F0-- From stsvs@wmdata.com Fri Aug 4 11:54:15 2000 From: stsvs@wmdata.com (Svensson, Stefan) Date: Fri, 4 Aug 2000 12:54:15 +0200 Subject: [Image-SIG] PNG PIL compression questions Message-ID: Hello, I have some qustions concerning compression behaviour and compression ratio when saving images in PNG-format with PIL. I have a scanned image that I have saved in Paintshop Pro: 1. First saved as TIFF LZW (38 kb) in Paintshop Pro and then opened in the Python interpretor and saved as PNG. The PNG file size become 38kb. Import Image im = Image.open("c:/image.tif") im.save("c:/image.png") 2. The same imaged saved in Paintshop Pro as a PNG (21 kb!) and when openened and saved in the Python interpretor as an PNG the file size become 55 kb! As an alternative to PIL and Python I have also tryed the Java Advaced Imaging API (JAI) and the resulting PNG file size is always 21 kb. But PIL is so much easier to use... I wonder why does this happen and are there any ways to improve the compression ratio and get a consistent behaviour when using PIL together with PNG? BTW, any plans for TIFF G4 support? I am using Windows NT4, Python 1.5.2 (binary release got from python.org) and PIL 1.0 (pil-win32-991101.zip binary release got from pythonware.com). Best regards, /Stefan Svensson stsvs@wmdata.com From rhyde99@email.msn.com Sun Aug 6 03:43:29 2000 From: rhyde99@email.msn.com (rhyde99) Date: Sat, 5 Aug 2000 19:43:29 -0700 Subject: [Image-SIG] TGA trouble Message-ID: <000801bfff50$1b352ec0$f1990f3f@oemcomputer> This is a multi-part message in MIME format. ------=_NextPart_000_0005_01BFFF15.6DF48240 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I would like to be able to load images rendered by the Lightflow = rendering tools (www.lightflowtech.com), but unfortunately it renders = only to a tga format not readable by PIL. It actually seems to be = trying to load it as a pcx image. I can provide a Lightflow-rendered = image upon request, so that anyone interested can check this out. I know little about the inner workings of this (or any) image file = format, so I can rule out writing my own decoder. does anyone have the = knowledge and willingness to help me with this? ------=_NextPart_000_0005_01BFFF15.6DF48240 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
I would like to be able to load images = rendered by=20 the Lightflow rendering tools (www.lightflowtech.com), but=20 unfortunately it renders only to a tga format not readable by PIL.  = It=20 actually seems to be trying to load it as a pcx image.  I can = provide=20 a Lightflow-rendered image upon request, so that anyone interested can = check=20 this out.
 
I know little about the inner workings = of this (or=20 any) image file format, so I can rule out writing my own decoder.  = does=20 anyone have the knowledge and willingness to help me with=20 this?
------=_NextPart_000_0005_01BFFF15.6DF48240-- From Joerg.Baumann@stud.informatik.uni-erlangen.de Mon Aug 7 20:58:33 2000 From: Joerg.Baumann@stud.informatik.uni-erlangen.de (Joerg Baumann) Date: Mon, 7 Aug 2000 21:58:33 +0200 (MET DST) Subject: [Image-SIG] TGA trouble In-Reply-To: <000801bfff50$1b352ec0$f1990f3f@oemcomputer> Message-ID: On Sat, 5 Aug 2000, rhyde99 wrote: > I would like to be able to load images rendered by the Lightflow rendering > tools (www.lightflowtech.com), but unfortunately it renders only to a tga > format not readable by PIL. It actually seems to be trying to load it as > a pcx image. I can provide a Lightflow-rendered image upon request, so > that anyone interested can check this out. > > I know little about the inner workings of this (or any) image file format, > so I can rule out writing my own decoder. does anyone have the > knowledge and willingness to help me with this? > Hi, There were 2 little bugs in PIL: * TgaImagePlugin.py could only read TGAs with an Image ID field of length zero. * TGAs with an Image ID field of length 0x0a were classified as PCX There is a diff for TgaImagePlugin.py and PcxImagePlugin.py below. File format information was obtained from www.wotsit.org (It's worth a to remember). If you have any problems with this diff, feel free to contact me, but I want to make certain that everyone understands that there is _no_ warranty for this free software. have fun, joerg Joerg Baumann joerg.baumann@stud.informatik.uni-erlangen.de +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Beware of bugs in the above code; I have only proved it correct, not tried it. Don Knuth *** PcxImagePlugin.py Wed Jun 7 15:17:04 2000 --- PcxImagePlugin.py Mon Aug 7 21:46:21 2000 *************** *** 31,35 **** def _accept(prefix): ! return ord(prefix[0]) == 10 and ord(prefix[1]) in [0, 2, 3, 5] class PcxImageFile(ImageFile.ImageFile): --- 31,35 ---- def _accept(prefix): ! return ord(prefix[0]) == 10 and ord(prefix[1]) in [0, 2, 3, 5] and ord(prefix[2]) == 1 and ord(prefix[3]) in [255, 2, 4,8] class PcxImageFile(ImageFile.ImageFile): *** TgaImagePlugin.py Wed Jun 7 15:17:04 2000 --- TgaImagePlugin.py Mon Aug 7 21:39:52 2000 *************** *** 42,47 **** def _accept(prefix): ! return prefix[0] == "\0" ! class TgaImageFile(ImageFile.ImageFile): --- 42,52 ---- def _accept(prefix): ! colormaptype = ord(prefix[1]) ! imagetype = ord(prefix[2]) ! if colormaptype==0: ! return imagetype in (2,3,10,11) ! elif colormaptype==1: ! return imagetype in (1,9) ! else: return [] class TgaImageFile(ImageFile.ImageFile): *************** *** 57,61 **** s = self.fp.read(18) ! id = ord(s[0]) colormaptype = ord(s[1]) --- 62,68 ---- s = self.fp.read(18) ! id_length = ord(s[0]) ! #read id_length bytes of image id descriptor ! id=self.fp.read(id_length) colormaptype = ord(s[1]) *************** *** 69,73 **** # validate header fields ! if id != 0 or colormaptype not in (0, 1) or\ self.size[0] <= 0 or self.size[1] <= 0 or\ depth not in (8, 16, 24, 32): --- 76,80 ---- # validate header fields ! if colormaptype not in (0, 1) or\ self.size[0] <= 0 or self.size[1] <= 0 or\ depth not in (8, 16, 24, 32): From fredrik@pythonware.com Tue Aug 8 13:55:58 2000 From: fredrik@pythonware.com (Fredrik Lundh) Date: Tue, 8 Aug 2000 14:55:58 +0200 Subject: [Image-SIG] bunch of pil errors References: <20000801.16531900@cricket.> Message-ID: <013401c00138$021a2c80$0900a8c0@SPIFF> nick bower wrote: > On a Mandrake 7.1 system, piddle wouldn't work with the PIL package > (1.0b) already installed: > > File "/usr/lib/python1.5/site-packages/PIL/ImageTk.py", line 113, in > paste > self.__photo.tk.call("PyImagingPhoto", self.__photo, block.id) > TclError: invalid command name "PyImagingPhoto" this means that Tkinter was built without PIL support. the easiest way to solve this is to upgrade to 1.0 final or later, since they allow you to build PIL with Tkinter support (instead of doing it the other way around...). > So maybe upgrading to 1.1 will fix the problem. But it won't compile: > > tar zxvf Imaging-1.1...tgz > cd Imaging-1.1/libImage > ./configure > make [...] > > make[1]: Entering directory `/home/nickb/Imaging-1.1' > make[1]: *** No rule to make target `/usr/lib/python1.5/config/Makefile', > needed by `sedscript'. Stop. > make[1]: Leaving directory `/home/nickb/Imaging-1.1' > make: *** [boot] Error 2 > > Call me a dummy, but I have no clue what this is saying. this (probably) means that you don't have the Python development files on your box. look for a "developer" package for mandrake, or rebuild Python from the source kit... From mmiller3@iupui.edu Tue Aug 8 19:51:28 2000 From: mmiller3@iupui.edu (Michael A. Miller) Date: 08 Aug 2000 13:51:28 -0500 Subject: [Image-SIG] passing parameters to functions used by Image.point? In-Reply-To: "Fredrik Lundh"'s message of "Wed, 8 Mar 2000 13:11:32 +0100" Message-ID: <87snsfk2mn.fsf_-_@lumen.med.iupui.edu> I'm trying to come up with an image thresholding class. I'd like to use the Image.point method to do the thresholding, but I'm not sure of how to make this work. Here's what I'm trying to do: class Thresholder: ... def apply_thresholds(self): self.out = self.image.point(lambda i: min(i,self.low)) This doesn't work because self.low is not accessible to the lambda. The traceback is self.out = self.image.point(lambda i: min(i,self.low)) NameError: self Can anyone help me with passing parameters such as self.low to lambda functions for Image.point? Even better - can anyone point me to an existing PIL image thresholding implementation? Regards, Mike -- Michael A. Miller mmiller3@iupui.edu Krannert Institute of Cardiology, IU School of Medicine Indiana Center for Vascular Biology and Medicine From Joerg.Baumann@stud.informatik.uni-erlangen.de Tue Aug 8 22:12:50 2000 From: Joerg.Baumann@stud.informatik.uni-erlangen.de (Joerg Baumann) Date: Tue, 8 Aug 2000 23:12:50 +0200 (MET DST) Subject: [Image-SIG] passing parameters to functions used by Image.point? In-Reply-To: <87snsfk2mn.fsf_-_@lumen.med.iupui.edu> Message-ID: On 8 Aug 2000, Michael A. Miller wrote: > class Thresholder: > ... > def apply_thresholds(self): > self.out = self.image.point(lambda i: min(i,self.low)) > try this: def apply_thresholds(self): self.out = self.image.point(eval("lambda i: min(i,"+`self.low`+")")) it will compile a suitable 1 argument function on the fly with a low-value hardwired during compilation. have fun, joerg Joerg Baumann joerg.baumann@stud.informatik.uni-erlangen.de +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Beware of bugs in the above code; I have only proved it correct, not tried it. Don Knuth From fredrik@pythonware.com Wed Aug 9 11:22:24 2000 From: fredrik@pythonware.com (Fredrik Lundh) Date: Wed, 9 Aug 2000 12:22:24 +0200 Subject: [Image-SIG] passing parameters to functions used by Image.point? References: <87snsfk2mn.fsf_-_@lumen.med.iupui.edu> Message-ID: <005701c001eb$ddc0b430$0900a8c0@SPIFF> michael miller wrote: > def apply_thresholds(self): > self.out = self.image.point(lambda i: min(i,self.low)) > > This doesn't work because self.low is not accessible to the > lambda. The traceback is > > self.out = self.image.point(lambda i: min(i,self.low)) > NameError: self > > Can anyone help me with passing parameters such as self.low to > lambda functions for Image.point? you can use default arguments to explicitly pass objects from your current local namespace to the lambda's namespace: self.out = self.image.point(lambda i, self=self: min(i, self.low)) or: self.out = self.image.point(lambda i, low=self.low: min(i, low)) see also: http://www.python.org/doc/FAQ.html#4.5 ::: or you can forget about lambdas and build the table "by hand": lut = range(0, low) + [low] * (256 - low) self.out = self.image.point(lut) (or use a for loop) From bowern@ses.curtin.edu.au Wed Aug 9 12:30:56 2000 From: bowern@ses.curtin.edu.au (Nick Bower) Date: Wed, 09 Aug 2000 11:30:56 GMT Subject: [Image-SIG] passing parameters to functions used by Image.point? In-Reply-To: <005701c001eb$ddc0b430$0900a8c0@SPIFF> References: <87snsfk2mn.fsf_-_@lumen.med.iupui.edu> <005701c001eb$ddc0b430$0900a8c0@SPIFF> Message-ID: <20000809.11305600@cricket.> > you can use default arguments to explicitly pass objects from > your current local namespace to the lambda's namespace: > self.out =3D self.image.point(lambda i, self=3Dself: min(i, self.l= ow)) > or: > self.out =3D self.image.point(lambda i, low=3Dself.low: min(i, low= )) > see also: http://www.python.org/doc/FAQ.html#4.5 wicked - I always wondered if there was a way to do this with lambdas =3D= ) From mmiller3@iupui.edu Thu Aug 10 00:29:01 2000 From: mmiller3@iupui.edu (Michael A. Miller) Date: 09 Aug 2000 18:29:01 -0500 Subject: [Image-SIG] dycom.py - DICOM from python Message-ID: <87g0oef1z6.fsf@lumen.med.iupui.edu> I've created a rather crude wrapper around David A. Clunie's dicom3tools (http://idt.net/~dclunie/dicom3tools.html). dycom.DICOM is a class that allows one to use a small subset of the dicom3tools from within python. Plus, it let me satisfy my urge for a cute play-on-python type name. An example of usage: MeasureDICOM.py (html) uses dycom.DICOM and tkinter to help me find the distance between two points in an image. Both can be found at http://php.iupui.edu/~mmiller3/python. Regards, Mike -- Michael A. Miller mmiller3@iupui.edu Krannert Institute of Cardiology, IU School of Medicine Indiana Center for Vascular Biology and Medicine From rglassco@mitretek.org Thu Aug 10 22:27:43 2000 From: rglassco@mitretek.org (Richard A. Glassco) Date: Thu, 10 Aug 2000 17:27:43 -0400 Subject: [Image-SIG] Installing Python Imaging Library Message-ID: <39931E4F.250C9EE9@mitretek.org> I just read the description of the Python Imaging Library and it looks great - it's just what I need. I downloaded the Windows version and unzipped it. But it's just sitting there. I can't find a word about how to install it. When I try to run it, I get a message that says "The _imaging C module is not installed". So how to I install the PIL in Python 1.5.2 in windows? -- Richard A. Glassco Principal Systems Modeler Mitretek Systems 600 Maryland Ave. Suite 755 Washington, DC 20024 Voice: (202) 488-5713 Fax: (202) 863-2988 e-mail: rglassco@mitretek.org From kcazabon" Message-ID: <088101c00318$2ded51c0$16107118@rct1.bc.wave.home.com> If you've also installed Mark Hammond's "Win32 Extensions", I've written an auto-installer for PIL. This will set up the Windows Registry and all that stuff for you automatically, but relies on some of Mark's Win32 stuff to do it. You can get the Win32 Extensions at: http://starship.python.net/crew/mhammond/downloads/win32all-132.exe My PIL installer can be found at: http://members.home.com/imaging/downloads/PIL1.0final.exe Kevin Cazabon. ----- Original Message ----- From: "Richard A. Glassco" To: ; Sent: Thursday, August 10, 2000 2:27 PM Subject: [Image-SIG] Installing Python Imaging Library > I just read the description of the Python Imaging Library and it looks > great - it's just what I need. I downloaded the Windows version and > unzipped it. But it's just sitting there. I can't find a word about > how to install it. When I try to run it, I get a message that says "The > _imaging C module is not installed". So how to I install the PIL in > Python 1.5.2 > in windows? > > -- > Richard A. Glassco > Principal Systems Modeler > Mitretek Systems > 600 Maryland Ave. Suite 755 > Washington, DC 20024 > Voice: (202) 488-5713 > Fax: (202) 863-2988 > e-mail: rglassco@mitretek.org > > > > _______________________________________________ > Image-SIG maillist - Image-SIG@python.org > http://www.python.org/mailman/listinfo/image-sig From hakuin@voicenet.com Sat Aug 12 03:40:22 2000 From: hakuin@voicenet.com (John Ferguson) Date: Fri, 11 Aug 2000 22:40:22 -0400 Subject: [Image-SIG] PIL works under NT but not Win98, where to look? Message-ID: <001901c00406$a9e2c5a0$877767cf@voicenet.com> I am trying to quickly get up to speed on Python for OpenGL programming. One of main obstacles is: >>> im = Image.open("C:\development\python\NeHe Ports\crate.bmp") >>> im.tostring("raw", "RGBX", 0, -1) Traceback (innermost last): File "", line 1, in ? File "C:\Program Files\Python\PIL\Image.py", line 325, in tostring self.load() File "C:\Program Files\Python\PIL\ImageFile.py", line 125, in load self.load_prepare() File "C:\Program Files\Python\PIL\ImageFile.py", line 175, in load_prepare self.im = Image.core.new(self.mode, self.size) File "C:\Program Files\Python\PIL\Image.py", line 40, in __getattr__ raise ImportError, "The _imaging C module is not installed" ImportError: The _imaging C module is not installed The exact same file pil-win32-991101.zip seems to work fine on NT, at least I can get the tostring call to work. However, my 98 box is not working. I have tested my python path: >>> print sys.path ['', 'C:\\Program Files\\Python', 'C:\\Program Files\\Python\\Lib\\plat-win', 'C:\\Program Files\\Python\\Lib', 'C:\\Program Files\\Python\\DLLs', 'C:\\Program Files\\Python\\Lib\\lib-tk', 'C:\\PROGRAM FILES\\PYTHON\\DLLs', 'C:\\PROGRAM FILES\\PYTHON\\lib', 'C:\\PROGRAM FILES\\PYTHON\\lib\\plat-win', 'C:\\PROGRAM FILES\\PYTHON\\lib\\lib-tk', 'C:\\PROGRAM FILES\\PYTHON', 'C:\\PROGRAM FILES\\PYTHON\\Numeric', 'C:\\PROGRAM FILES\\PYTHON\\PIL'] Which includes PIL, and lib-tk which I think are the main places for the Image tools. I installed python using: py152.exe and the PIL library seems to be for the same version. I also installed PyOpenGL. Any ideas on how to address this? Thanks, John Ferguson From hakuin@voicenet.com Sat Aug 12 04:34:06 2000 From: hakuin@voicenet.com (John Ferguson) Date: Fri, 11 Aug 2000 23:34:06 -0400 Subject: [Image-SIG] Re: PIL works under NT but not Win98, where to look? Doh.... Never mind found it. Message-ID: <000c01c0040e$2bcecbc0$995d67cf@voicenet.com> ----- Original Message ----- From: John Ferguson To: Sent: Friday, August 11, 2000 10:40 PM Subject: PIL works under NT but not Win98, where to look? > I am trying to quickly get up to speed on Python for OpenGL programming. > One of main obstacles is: > > >>> im = Image.open("C:\development\python\NeHe Ports\crate.bmp") > >>> im.tostring("raw", "RGBX", 0, -1) > Traceback (innermost last): > File "", line 1, in ? > File "C:\Program Files\Python\PIL\Image.py", line 325, in tostring > self.load() > File "C:\Program Files\Python\PIL\ImageFile.py", line 125, in load > self.load_prepare() > File "C:\Program Files\Python\PIL\ImageFile.py", line 175, in load_prepare > self.im = Image.core.new(self.mode, self.size) > File "C:\Program Files\Python\PIL\Image.py", line 40, in __getattr__ > raise ImportError, "The _imaging C module is not installed" > ImportError: The _imaging C module is not installed > > The exact same file pil-win32-991101.zip seems to work fine on NT, at least > I can get the tostring call to work. However, my 98 box is not working. > > I have tested my python path: > > >>> print sys.path > ['', 'C:\\Program Files\\Python', 'C:\\Program > Files\\Python\\Lib\\plat-win', 'C:\\Program Files\\Python\\Lib', > 'C:\\Program Files\\Python\\DLLs', 'C:\\Program > Files\\Python\\Lib\\lib-tk', 'C:\\PROGRAM FILES\\PYTHON\\DLLs', 'C:\\PROGRAM > FILES\\PYTHON\\lib', 'C:\\PROGRAM FILES\\PYTHON\\lib\\plat-win', > 'C:\\PROGRAM FILES\\PYTHON\\lib\\lib-tk', 'C:\\PROGRAM FILES\\PYTHON', > 'C:\\PROGRAM FILES\\PYTHON\\Numeric', 'C:\\PROGRAM FILES\\PYTHON\\PIL'] > > Which includes PIL, and lib-tk which I think are the main places for the > Image tools. > > I installed python using: py152.exe and the PIL library seems to be for the > same version. I also installed PyOpenGL. > > Any ideas on how to address this? > > Thanks, > > John Ferguson > > > From rtrocca@libero.it Thu Aug 17 14:58:16 2000 From: rtrocca@libero.it (Riccardo Trocca) Date: Thu, 17 Aug 2000 15:58:16 +0200 Subject: [Image-SIG] Making Imaging 1.1 work with MacPython Message-ID: Hello, I'm trying to make Imaging 1.1 work with MacPython. Anl older version of this library is included with the standard MacPython distribution (1.0bx). I'm able to compile everything and the coretest app works. But when I try to display on an image from Python it complains about error -8 (Bad config in decoder) or, in case of GIF images it chrashes everything and MacPython quits. Any hints? Riccardo Trocca From patperry@stanford.edu Thu Aug 17 19:13:21 2000 From: patperry@stanford.edu (Patrick Perry) Date: Thu, 17 Aug 2000 11:13:21 -0700 (PDT) Subject: [Image-SIG] portability issue in ImConfig.h In-Reply-To: <20000817175849.91E7D1CC69@dinsdale.python.org> Message-ID: Hi guys, I was browsing through the source of PIL, and was a little confused when I came across ImConfig.h (in the libImaging directory). This file is full of lines like: #define SIZEOF_CHAR 1 #define SIZEOF_DOUBLE 8 #define SIZEOF_FLOAT 4 Why are these values hard coded instead of using the "sizeof" macro that's part of any ANSI C compiler??? The *only* size that's guaranteed is char-- the size of float, double, etc. can change from platform to platform. I hope I'm missing something here-- if I am, fill me in. Otherwise, let's change ImConfig.h to be a little more ANSI compliant. Patrick From schorsch@schorsch.com Thu Aug 17 20:03:44 2000 From: schorsch@schorsch.com (Georg Mischler) Date: Thu, 17 Aug 2000 15:03:44 -0400 (EDT) Subject: [Image-SIG] portability issue in ImConfig.h In-Reply-To: Message-ID: Patrick Perry wrote: > > Hi guys, > > I was browsing through the source of PIL, and was a little confused when I > came across ImConfig.h (in the libImaging directory). This file is full > of lines like: > > #define SIZEOF_CHAR 1 > #define SIZEOF_DOUBLE 8 > #define SIZEOF_FLOAT 4 > > Why are these values hard coded instead of using the "sizeof" macro that's > part of any ANSI C compiler??? The *only* size that's guaranteed is > char-- the size of float, double, etc. can change from platform to > platform. I hope I'm missing something here-- if I am, fill me > in. Otherwise, let's change ImConfig.h to be a little more ANSI > compliant. That depends on your definition of "hard coded". The ImConfig.h file is generated by the configure script, which probably uses exactly the sizeof operator you're advocating. The nice thing with doing it this way is that it's garanteed to be done *before* compile time. As far as I know, this is common practise when "size matters". ANSI defines sizeof to be evaluated at compile time, but not earlier. After all, it's an operator (not a macro!), and as such implemented by the compiler. Unfortunately, we need it's results already in the preprocessing stage, which leaves the chosen approach as the only truly portable solution. Have fun! -schorsch -- Georg Mischler -- simulations developer -- schorsch at schorsch.com +schorsch.com+ -- lighting design tools -- http://www.schorsch.com/ From denis.frere@aragne.com Sat Aug 19 22:31:01 2000 From: denis.frere@aragne.com (=?iso-8859-1?Q?Denis_Fr=E8re?=) Date: Sat, 19 Aug 2000 23:31:01 +0200 Subject: [Image-SIG] ellipse in PIL doesn't appear ... ? Message-ID: <000101c00a24$c61f3bd0$180211ac@zantafio.DARKSIDE> Hello, I just started playing with PIL. I've read the docs : great ! I managed to create a new image. There came my first surprise : colors are not RGB but BRG !? Then I used ImageDraw : I can draw rectangles, lines, polygons, points ... But I can't manage to draw a circle or an ellipse. (I didn't try arcs and pies, I guess it would be the same). What means xy in the case of an ellipse ? I'm asked a quad-tuple : - origin point + height + width just like in Pdfgen ? - rectangle box ? I tried lots of combinations and nothing show up in the image. The code of ImageDraw isn't of much help. I found nothing about ellipse through the search engine. I tried PIL 1.0 on a Winnt4 platform. Thanks if you can help. Denis spirou@p3b.org From jwt@OnJapan.net Sun Aug 20 01:19:13 2000 From: jwt@OnJapan.net (Jim Tittsler) Date: Sun, 20 Aug 2000 09:19:13 +0900 Subject: [Image-SIG] ellipse in PIL doesn't appear ... ? In-Reply-To: <000101c00a24$c61f3bd0$180211ac@zantafio.DARKSIDE>; from denis.frere@aragne.com on Sat, Aug 19, 2000 at 11:31:01PM +0200 References: <000101c00a24$c61f3bd0$180211ac@zantafio.DARKSIDE> Message-ID: <20000820091913.A25446@mail.dskk.co.jp> On Sat, Aug 19, 2000 at 11:31:01PM +0200, Denis Frère wrote: > What means xy in the case of an ellipse ? I believe it is the bounding rectangle that contains the ellipse. import Image,ImageDraw im = Image.new('RGB', (400,400), (0xFF,0xFF,0xFF)) id = ImageDraw.Draw(im) # draw a red elipse outlined in blue that fits in (200,200) to (395,300) id.ellipse((200,200,395,300), fill=(0xFF,0,0), outline=(0,0,0xFF)) im.save("test.png") -- Jim Tittsler, Tokyo Python Starship http://starship.python.net/crew/jwt/ From manyong@gnu.org Sun Aug 20 22:32:11 2000 From: manyong@gnu.org (Man-Yong Lee) Date: Mon, 21 Aug 2000 06:32:11 +0900 Subject: [Image-SIG] show() bug in Image.py of PIL 1.1 (maybe) Message-ID: <39A04E5B.226AFA07@gnu.org> Hi, Image-SIG guys I'm new to this sig. I think there is a bug in show()ing Image object via ``xv'' in case there's no support of Tkinter. My environment is like this: Red Hat Linux 6.2 Python 1.52 PIL 1.1 Around the line 975 of Image.py: def _showxv(self, title=None, command=None): if os.name == "nt": format = "BMP" if not command: command = "start" else: format = None if not command: command = "xv" if title: command = command + " -name \"%s\"" % title Following the codes above, the value of format is always None when os.name is not "nt" base = getmodebase(self.mode) if base != self.mode and self.mode != "1": file = self.convert(base)._dump(format=format) else: file = self._dump(format=format) So, self._dump(format=format) will be called as self._dump(format=None). This makes these codes raise TypeError exception! (around the line 312) def _dump(self, file=None, format="PPM"): import tempfile if not file: file = tempfile.mktemp() self.load() if format == "PPM": self.im.save_ppm(file) else: file = file + "." + format ^^^^^^^^^^^^^^^^^^^^^^^^^^ self.save(file, format) return file Because format is always None, ``file = file + "." + format'' raise TypeError exception. (string type + None!) My dirty hack is like this: Before calling file = self._dump(format=format), I inserts these lines. if not format: # FIXME format = self.format if not format: format = 'PPM' file = self._dump(format=format) Thanks for reading this. Am I wrong? I want your comment. __ Bryan Lee Linux Korea, Inc. From juha.o.ylitalo@nokia.com Tue Aug 22 18:07:22 2000 From: juha.o.ylitalo@nokia.com (Juha Ylitalo) Date: Tue, 22 Aug 2000 20:07:22 +0300 Subject: [Image-SIG] Large PCD image sizes and PIL Message-ID: <20000822200722.B456@shoes.st-paul> --oLBj+sq0vYjzfsbl Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Currently PIL (v1.1) supports only small PhotoCD (=PCD) resolutions (=192x128, 384x256 and 768x512). Is their any on-going work to get bigger resolutions (=1536x1024 and 3072x2048) supported as well or are there some known reasons, why it wouldn't be possible ? I am wondering it because, I have small python application for merging PhotoCD pictures and bunch of configuration files into HTML and jpg based photo album (its sort of exercise for me:). I am currently using pcdtoppm (-j) from xpcd (http://www.strusel007.de/linux/xpcd.html) to make pcd to jpg convertions, but I would still like to replace it with PIL stuff, if possible. -- Juha Ylitalo juha.o.ylitalo@nokia.com KOM 5/3 312 http://wwwinhel.ntc.nokia.com/~jylitalo +358 40 562 6152 http://www.iki.fi/~jylitalo "Some tools are used, because its policy, others because they are good." --oLBj+sq0vYjzfsbl Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.2 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE5orNKs9o7tOc1jEMRAuagAJ91crFj2NUrVs1IYVEVXTd7uawOHACgn78w yQKIiEJdqZIFkbxnjYoHYSw= =xgCR -----END PGP SIGNATURE----- --oLBj+sq0vYjzfsbl-- From kcaza@cymbolic.com Wed Aug 23 17:14:18 2000 From: kcaza@cymbolic.com (kcaza@cymbolic.com) Date: Wed, 23 Aug 2000 09:14:18 -0700 Subject: [Image-SIG] Image MetaData for resolution of file... Message-ID: <88256944.005933D9.00@mail.cymbolic.com> Is there any way to have PIL save the resolution of a file (dpi) when saving an image? As it is, everything defaults to the standard 72dpi (I assume because it omits the tag altogether), which causes problems when trying to print images in most programs without re-sizing. For my applications, I need to print images at EXACT sizes, and if the dpi tag is missing, it's very difficult to do. The file formats that it's most important to me for are TIFF, BMP, EPS and PDF, but I would also love to have it work in others like GIF, PNG, and TGA. Can this be done? I'd gladly code it, but I don't know enough about the file structures for these formats to start adding tags right now. Any help is appreciated, Kevin Cazabon From drusch@globalcrossing.com Wed Aug 23 20:24:55 2000 From: drusch@globalcrossing.com (Daniel Rusch) Date: Wed, 23 Aug 2000 14:24:55 -0500 Subject: [Image-SIG] Problems running / installing PIL on SunOS Message-ID: <39A42507.AE4C94E3@globalcrossing.com> I have installed PIL (1.0) on my box and I wrote the foolowing test code: import PIL, PIL.Image i = PIL.Image.open('/home/caps/test/zope/Extensions/gclogo_color.gif') i.convert('RGB') lines 1 nad 2 work fine, line three generates the following error: File "test.py", line 3, in ? i.convert('RGB') File "/home/caps/test/zope/lib/python1.5/site-packages/PIL/Image.py", line 397, in convert self.load() File "ImageFile.py", line 125, in load File "ImageFile.py", line 175, in load_prepare File "/home/caps/test/zope/lib/python1.5/site-packages/PIL/Image.py", line 40, in __getattr__ raise ImportError, "The _imaging C module is not installed" ImportError: The _imaging C module is not installed If I run the following code: import _imaging I get this error: Traceback (innermost last): File "", line 1, in ? ImportError: ld.so.1: python: fatal: relocation error: file ./_imaging.so: symbol XFreeColormap: referenced symbol not found Any thoughts, DR P.S. Please reply all, as I just subscribed to this sig From fredrik@pythonware.com Thu Aug 24 14:09:24 2000 From: fredrik@pythonware.com (Fredrik Lundh) Date: Thu, 24 Aug 2000 15:09:24 +0200 Subject: [Image-SIG] Large PCD image sizes and PIL References: <20000822200722.B456@shoes.st-paul> Message-ID: <01e101c00dcc$87579f90$0900a8c0@SPIFF> juha wrote: > Currently PIL (v1.1) supports only small PhotoCD (=PCD) resolutions > (=192x128, 384x256 and 768x512). Is their any on-going work to get > bigger resolutions (=1536x1024 and 3072x2048) supported as well or are > there some known reasons, why it wouldn't be possible ? legal issues. images up to 768x512 are stored as uncompressed pixel data (using a custom colour space), but higher resolutions use a proprietary encoding method. From spirou@aragne.com Thu Aug 24 20:08:53 2000 From: spirou@aragne.com (Denis) Date: Thu, 24 Aug 2000 21:08:53 +0200 Subject: [Image-SIG] Drawing text In-Reply-To: <20000820091913.A25446@mail.dskk.co.jp>; from jwt@OnJapan.net on Sun, Aug 20, 2000 at 09:19:13AM +0900 References: <000101c00a24$c61f3bd0$180211ac@zantafio.DARKSIDE> <20000820091913.A25446@mail.dskk.co.jp> Message-ID: <20000824210853.D25951@aragne.com> Le Sun, Aug 20, 2000 at 09:19:13AM +0900, Jim Tittsler pianota: > On Sat, Aug 19, 2000 at 11:31:01PM +0200, Denis Frère wrote: > > What means xy in the case of an ellipse ? > > I believe it is the bounding rectangle that contains the ellipse. > > import Image,ImageDraw > im = Image.new('RGB', (400,400), (0xFF,0xFF,0xFF)) > id = ImageDraw.Draw(im) > # draw a red elipse outlined in blue that fits in (200,200) to (395,300) > id.ellipse((200,200,395,300), fill=(0xFF,0,0), outline=(0,0,0xFF)) > im.save("test.png") Thank you Jim. I used colors with one big hex (0xffaacc) in place of a tuple (thats why my colors were BGR instead of RGB) and my box was upside down. Your few lines put me on the right way. Could you (or someone else) send me a few lines more with a text drawing sample ? -- Denis FRERE P3B : Club Free-Pytho-Linuxien Caroloregien http://www.p3b.org Aragne : Internet - Reseaux - Formations http://www.aragne.com From klimek@grc.nasa.gov Thu Aug 31 14:09:19 2000 From: klimek@grc.nasa.gov (Robert B. Klimek) Date: Thu, 31 Aug 2000 09:09:19 -0400 Subject: [Image-SIG] tif file save problem Message-ID: <4.1.20000831090038.00c67de0@parrot.grc.nasa.gov> Hello, I've come across a possible bug in PIL. There is something weird with .tif or .bmp images that are saved by PIL. If you load a .tif image that was previously saved by PIL and try to paste and image into it, it will crash the program. Below is a test case from Idle but the same happens in my python program. My OS is NT 4, sp 3. I'm using PIL 1.0. Is this fixed in PIL 1.1? Is there a fix? >>> import Image >>> im = Image.open('c:\\Images\\im001.tif') >>> im.save('c:\\Images\\test1.tif') >>> im2 = Image.open('c:\\Images\\test1.tif') >>> roi = im2.crop((10,10,50,50)) >>> im2.paste(roi,(10,10,50,50)) The last line (paste) crashes the program and produces this error message. Error messages: On Win98 I get: This program has performed an illegal operation and will be shut down. If the problem persists, contact the program vendor. Pythonw caused an invalid page fault in module _IMAGING.DLL at... On NT I get: The instruction at "0x00..." referenced memory at "0x00...". The memory could not be written. ------------------------------------------------- Robert B. Klimek NASA Glenn Research Center robert.klimek@grc.nasa.gov (216) 433-2837 -------------------------------------------------- From fredrik@pythonware.com Thu Aug 31 14:34:04 2000 From: fredrik@pythonware.com (Fredrik Lundh) Date: Thu, 31 Aug 2000 15:34:04 +0200 Subject: [Image-SIG] tif file save problem References: <4.1.20000831090038.00c67de0@parrot.grc.nasa.gov> Message-ID: <001401c01350$221b4da0$0900a8c0@SPIFF> robert wrote: > I've come across a possible bug in PIL. There is something weird with .tif > or .bmp images that are saved by PIL. If you load a .tif image that was > previously saved by PIL and try to paste and image into it, it will crash > the program. Below is a test case from Idle but the same happens in my > python program. My OS is NT 4, sp 3. > > I'm using PIL 1.0. Is this fixed in PIL 1.1? Is there a fix? > > >>> import Image > >>> im = Image.open('c:\\Images\\im001.tif') > >>> im.save('c:\\Images\\test1.tif') > >>> im2 = Image.open('c:\\Images\\test1.tif') > >>> roi = im2.crop((10,10,50,50)) > >>> im2.paste(roi,(10,10,50,50)) > > The last line (paste) crashes the program and produces this error message. it's a known bug; PIL uses memory mapping for some file formats on Windows, and paste fails to realize that it has to "copy on write"... adding an explicit copy should fix this one: > >>> im2 = Image.open('c:\\Images\\test1.tif') > >>> im2 = im2.copy() # make sure we have a writable copy > >>> roi = im2.crop((10,10,50,50)) > >>> im2.paste(roi,(10,10,50,50)) From klimek@grc.nasa.gov Thu Aug 31 15:45:56 2000 From: klimek@grc.nasa.gov (Robert B. Klimek) Date: Thu, 31 Aug 2000 10:45:56 -0400 Subject: [Image-SIG] tif file save problem In-Reply-To: <001401c01350$221b4da0$0900a8c0@SPIFF> References: <4.1.20000831090038.00c67de0@parrot.grc.nasa.gov> Message-ID: <4.1.20000831103715.00c669a0@parrot.grc.nasa.gov> At 03:34 PM 8/31/00 +0200, you wrote: >robert wrote: >> I've come across a possible bug in PIL. There is something weird with .tif >> or .bmp images that are saved by PIL. If you load a .tif image that was >> previously saved by PIL and try to paste and image into it, it will crash >> the program. Below is a test case from Idle but the same happens in my >> python program. My OS is NT 4, sp 3. >> >> I'm using PIL 1.0. Is this fixed in PIL 1.1? Is there a fix? >> >> >>> import Image >> >>> im = Image.open('c:\\Images\\im001.tif') >> >>> im.save('c:\\Images\\test1.tif') >> >>> im2 = Image.open('c:\\Images\\test1.tif') >> >>> roi = im2.crop((10,10,50,50)) >> >>> im2.paste(roi,(10,10,50,50)) >> >> The last line (paste) crashes the program and produces this error message. > >it's a known bug; PIL uses memory mapping for some file >formats on Windows, and paste fails to realize that it has >to "copy on write"... > >adding an explicit copy should fix this one: > >> >>> im2 = Image.open('c:\\Images\\test1.tif') >> >>> im2 = im2.copy() # make sure we have a writable copy >> >>> roi = im2.crop((10,10,50,50)) >> >>> im2.paste(roi,(10,10,50,50)) Fredrik, That indeed does the trick. Thanks much! The funny thing about it was that it didn't do it with any other image files except the ones that PIL saved. Another question for you. What are new features of PIL 1.1 compared to 1.0? Is there a ducument somewhere that lists this? Bob ------------------------------------------------- Robert B. Klimek NASA Glenn Research Center robert.klimek@grc.nasa.gov (216) 433-2837 --------------------------------------------------