From zabaione at uk2.net Wed Nov 1 11:51:04 2006 From: zabaione at uk2.net (Martin Dunschen) Date: Wed, 01 Nov 2006 10:51:04 +0000 Subject: [Image-SIG] ImageFont ttf and the letter 'f' Message-ID: <45487C18.6090002@uk2.net> Hi I am using ImageFont and ImagDraw (version 1.1.5) on WindowsXP to display large font text. I noticed that the letter 'f' has a smudge top left from the character, the rendering is wrong there. I have not tried all fonts, but I can see it in TIMES.TTF and ARIAL.TTF. Here is a bit of code that shows the problem: import Image, ImageDraw, ImageFont im = Image.new('RGB', (100, 100)) imd = ImageDraw.Draw(im) imf = ImageFont.truetype('TIMES.TTF', 50) imd.text((10, 10), 'f', font=imf) im.save('letterf.png') im.show() Can this be fixed easily? Thanks Martin From chrisspen at gmail.com Mon Nov 6 19:38:44 2006 From: chrisspen at gmail.com (Chris S) Date: Mon, 6 Nov 2006 13:38:44 -0500 Subject: [Image-SIG] Array to Image to Array Message-ID: I'm trying to "smooth" a 2D array of floats by converting it to a PIL image, blurring it, then converting it back to an array. However, I can find no practical way to convert arrays to and from PIL. I've found http://effbot.org/zone/pil-numpy.htm but it was written 8 years ago for Numeric and doesn't appear to work with the current version of Numpy and PIL. Does anyone know how to adapt this code to work correctly with the current libraries? I also noticed that PIL 1.1.6b2 has a new fromarray method, but all my attempts to compile it on FC5 fail with: _imagingtk.c:20:16: error: tk.h: No such file or directory _imagingtk.c:23: error: expected ')' before '*' token _imagingtk.c:31: error: expected specifier-qualifier-list before 'Tcl_Interp' _imagingtk.c: In function '_tkinit': _imagingtk.c:37: error: 'Tcl_Interp' undeclared (first use in this function) _imagingtk.c:37: error: (Each undeclared identifier is reported only once _imagingtk.c:37: error: for each function it appears in.) _imagingtk.c:37: error: 'interp' undeclared (first use in this function) _imagingtk.c:45: error: expected expression before ')' token _imagingtk.c:51: error: 'TkappObject' has no member named 'interp' _imagingtk.c:55: warning: implicit declaration of function 'TkImaging_Init' error: command 'gcc' failed with exit status 1 Any help resolving this issue is appreciated. Thanks, Chris P.S. Sorry if this is double posted. I tried sending from Gmane but when the post didn't appear after several hours I subscribed directly to the list instead. From Chris.Barker at noaa.gov Tue Nov 7 00:01:53 2006 From: Chris.Barker at noaa.gov (Christopher Barker) Date: Mon, 06 Nov 2006 15:01:53 -0800 Subject: [Image-SIG] Array to Image to Array In-Reply-To: References: Message-ID: <454FBEE1.5030909@noaa.gov> You're missing the headers for TK. You probably need to install something like python-devel or tcl-devel packages. but you should be able to use older PIL to do this, just not quite as efficiently as with the array interface. See tostring and fromstring in both PIL and numpy. -Chris Chris S wrote: > I'm trying to "smooth" a 2D array of floats by converting it to a PIL > image, blurring it, then converting it back to an array. However, I > can find no practical way to convert arrays to and from PIL. > > I've found http://effbot.org/zone/pil-numpy.htm but it was written 8 > years ago for Numeric and doesn't appear to work with the current > version of Numpy and PIL. Does anyone know how to adapt this code to > work correctly with the current libraries? > > I also noticed that PIL 1.1.6b2 has a new fromarray method, but all my > attempts to compile it on FC5 fail with: > > _imagingtk.c:20:16: error: tk.h: No such file or directory > _imagingtk.c:23: error: expected ')' before '*' token > _imagingtk.c:31: error: expected specifier-qualifier-list before 'Tcl_Interp' > _imagingtk.c: In function '_tkinit': > _imagingtk.c:37: error: 'Tcl_Interp' undeclared (first use in this function) > _imagingtk.c:37: error: (Each undeclared identifier is reported only once > _imagingtk.c:37: error: for each function it appears in.) > _imagingtk.c:37: error: 'interp' undeclared (first use in this function) > _imagingtk.c:45: error: expected expression before ')' token > _imagingtk.c:51: error: 'TkappObject' has no member named 'interp' > _imagingtk.c:55: warning: implicit declaration of function 'TkImaging_Init' > error: command 'gcc' failed with exit status 1 > > Any help resolving this issue is appreciated. > > Thanks, > Chris > > P.S. Sorry if this is double posted. I tried sending from Gmane but > when the post didn't appear after several hours I subscribed directly > to the list instead. > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig -- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker at noaa.gov From nadavh at visionsense.com Tue Nov 7 04:42:50 2006 From: nadavh at visionsense.com (Nadav Horesh) Date: Tue, 7 Nov 2006 05:42:50 +0200 Subject: [Image-SIG] Array to Image to Array Message-ID: <07C6A61102C94148B8104D42DE95F7E8FCB21A@exchange2k.envision.co.il> 1. You probably have to install tk/tcl development package (I was a redhat user few years ago, so that is what I can recall) 2. Blurring is carried via a convolution, so probably a faster and more flexible method is to use ndimage (numpy.numarray.nd_image), or scipy. Nadav -----Original Message----- From: image-sig-bounces at python.org [mailto:image-sig-bounces at python.org] On Behalf Of Chris S Sent: Monday, November 06, 2006 20:39 To: image-sig at python.org Subject: [Image-SIG] Array to Image to Array I'm trying to "smooth" a 2D array of floats by converting it to a PIL image, blurring it, then converting it back to an array. However, I can find no practical way to convert arrays to and from PIL. I've found http://effbot.org/zone/pil-numpy.htm but it was written 8 years ago for Numeric and doesn't appear to work with the current version of Numpy and PIL. Does anyone know how to adapt this code to work correctly with the current libraries? I also noticed that PIL 1.1.6b2 has a new fromarray method, but all my attempts to compile it on FC5 fail with: _imagingtk.c:20:16: error: tk.h: No such file or directory _imagingtk.c:23: error: expected ')' before '*' token _imagingtk.c:31: error: expected specifier-qualifier-list before 'Tcl_Interp' _imagingtk.c: In function '_tkinit': _imagingtk.c:37: error: 'Tcl_Interp' undeclared (first use in this function) _imagingtk.c:37: error: (Each undeclared identifier is reported only once _imagingtk.c:37: error: for each function it appears in.) _imagingtk.c:37: error: 'interp' undeclared (first use in this function) _imagingtk.c:45: error: expected expression before ')' token _imagingtk.c:51: error: 'TkappObject' has no member named 'interp' _imagingtk.c:55: warning: implicit declaration of function 'TkImaging_Init' error: command 'gcc' failed with exit status 1 Any help resolving this issue is appreciated. Thanks, Chris P.S. Sorry if this is double posted. I tried sending from Gmane but when the post didn't appear after several hours I subscribed directly to the list instead. _______________________________________________ Image-SIG maillist - Image-SIG at python.org http://mail.python.org/mailman/listinfo/image-sig From maxerickson at gmail.com Tue Nov 7 12:16:29 2006 From: maxerickson at gmail.com (Max Erickson) Date: Tue, 7 Nov 2006 11:16:29 +0000 (UTC) Subject: [Image-SIG] Array to Image to Array References: Message-ID: "Chris S" wrote: > I'm trying to "smooth" a 2D array of floats by converting it to a > PIL image, blurring it, then converting it back to an array. > However, I can find no practical way to convert arrays to and > from PIL. > > I've found http://effbot.org/zone/pil-numpy.htm but it was > written 8 years ago for Numeric and doesn't appear to work with > the current version of Numpy and PIL. Does anyone know how to > adapt this code to work correctly with the current libraries? > Change a.typecode() to a.dtype and import Numeric to from numpy.core import numeric. Fix numeric not to be capitalized. I'm guessing a bit, I did a similar fix for an earlier version of numpy and a.dtype used to be a.dtypechar, but I think it should work. max From soydw at earchi.com Fri Nov 10 09:50:01 2006 From: soydw at earchi.com (Gertie Spencer) Date: Fri, 10 Nov 2006 09:50:01 +0100 Subject: [Image-SIG] foundry digital Message-ID: <6B0FB15.3FDC33C3718@yogateachersassoc.org> An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20061110/d23f88d3/attachment.htm -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: image/gif Size: 6384 bytes Desc: not available Url : http://mail.python.org/pipermail/image-sig/attachments/20061110/d23f88d3/attachment.gif From ronald at ivec.org Mon Nov 13 09:04:33 2006 From: ronald at ivec.org (Ronald Jones) Date: Mon, 13 Nov 2006 16:04:33 +0800 Subject: [Image-SIG] patch to tiff image plugin Message-ID: <1163405073.4540.21.camel@sambucca.ivec.org> Hello, Attached is a patched tiff image plugin for 1.1.6b2. The changes are: * Added support for signed short, signed long and signed rational data types * Added support for saving in big endian mode * Added support for tiff images that have pointers to another IDF inside the primary IDF Any problems let me know. regards, Ron -- Ronald Jones iVEC, 'The hub of advanced computing in Western Australia' 26 Dick Perry Avenue, Technology Park Kensington WA 6151 Australia Phone: +61 8 6436 8633 Fax: +61 8 6436 8555 Email: ronald.jones at ivec.org WWW: http://www.ivec.org -------------- next part -------------- A non-text attachment was scrubbed... Name: TiffImagePlugin-1.1.6b2-patched.py Type: text/x-python Size: 25818 bytes Desc: not available Url : http://mail.python.org/pipermail/image-sig/attachments/20061113/b5299e4f/attachment.py From kacen at comcast.net Mon Nov 13 22:45:52 2006 From: kacen at comcast.net (Steve Kacenjar) Date: Mon, 13 Nov 2006 16:45:52 -0500 Subject: [Image-SIG] im.show() error Message-ID: <1163454352.23563.5.camel@localhost.localdomain> I have just installed the Python Imaging Library (PIL) on my fedora core 5 LINUX system and began going through he tutorial in loading and displaying an image. I tried to specifically bring up a jpg image and received the following error with the command im.show(): sh: xv: command not found Any suggestions how to address this error would be greatly appreciated. Thanks. Steve PS. before this step I: (1) import Image (2) im = Image.open('cluster.jpg') From gwidion at mpc.com.br Mon Nov 13 04:23:23 2006 From: gwidion at mpc.com.br (Joao S. O. Bueno Calligaris) Date: Mon, 13 Nov 2006 01:23:23 -0200 Subject: [Image-SIG] im.show() error In-Reply-To: <1163454352.23563.5.camel@localhost.localdomain> References: <1163454352.23563.5.camel@localhost.localdomain> Message-ID: <200611130123.24846.gwidion@mpc.com.br> On Monday 13 November 2006 07:45 pm, Steve Kacenjar wrote: > I have just installed the Python Imaging Library (PIL) on my fedora > core 5 LINUX system and began going through he tutorial in loading > and displaying an image. I tried to specifically bring up a jpg > image and received the following error with the command im.show(): > > sh: xv: command not found > > Any suggestions how to address this error would be greatly > appreciated. Thanks. > > Steve > > PS. before this step I: > > (1) import Image > (2) im = Image.open('cluster.jpg') > The problem is that the utility "xv" is hardcoded into the PIL code as the default application to open to show up an image. XV has licensing problems and is not included in most GNU/Linux distributions. But all you have to do is to have any application named "xv" that accepts an image name on the command line and displays that image. I usually just create a symbolic link of xv to the kde kuickshow program - buyt many others would do. js -><- From sergiao at fastwebnet.it Tue Nov 14 09:02:01 2006 From: sergiao at fastwebnet.it (sergiao at fastwebnet.it) Date: Tue, 14 Nov 2006 09:02:01 +0100 (CET) Subject: [Image-SIG] separate TIFF Message-ID: <3190139.313691163491321617.JavaMail.defaultUser@defaultHost> Hi guys, i have a TIFF image of 10 pages, i have to make more file of 2 pages with a python script, what i have to do? sorry for my bad english From fredrik at pythonware.com Tue Nov 14 13:43:33 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 14 Nov 2006 13:43:33 +0100 Subject: [Image-SIG] im.show() error References: <1163454352.23563.5.camel@localhost.localdomain> <200611130123.24846.gwidion@mpc.com.br> Message-ID: Joao S. O. Bueno Calligaris wrote: > The problem is that the utility "xv" is hardcoded into the PIL code as > the default application to open to show up an image. you can override this by passing in a command= argument to im.show: im.show(command="myviewer") From tom at t0mb.net Tue Nov 14 22:19:47 2006 From: tom at t0mb.net (tom) Date: Tue, 14 Nov 2006 21:19:47 +0000 Subject: [Image-SIG] Monochrome image tostring length problems Message-ID: <455A32F3.80109@t0mb.net> Hi guys, I'm having a real problem at the moment trying to figure out how to pass strings of 1bit image data between PIL and the g15daemon which supports the logitech g15 keyboards lcd. Basically, it's 160x143 in resolution. The g15 python bindings have two methods of note. The loader_10_ascii_format method loads a file which is formatted as 1001101110001 etc, and converts it in to a string of the form \x00\x01\x01\x00 etc.... this string has a len of 6880, which is the length it should be, being 160x43. If i try to do anything with a PIL created image initialised like i = Image.new('1', (160, 43)) and then, with s being the string returned from the g15 ascii loader, do something like this i.fromstring(s) then you have a problem illustrated like so: len(i.tostring('raw', '1')) returns 860 (6880 / 8) len(i.tostring('raw', '1').encode('string-escape') returns 3440 half the number i need... I cannot send this string to the g15daemon.set_buffer method as it needs to be a string which is 6880 in length see here for part of my ipython session which illustrates the issue. In [65]: i = Image.new("1", (160, 43)) In [66]: s = g15daemon.loader_ascii_10_format('lcd.ascii') In [67]: len s -------> len(s) Out[67]: 6880 In [68]: len i.tostring() -------> len(i.tostring()) Out[68]: 860 In [69]: len i.tostring().encode('string-escape') -------> len(i.tostring().encode('string-escape')) Out[69]: 3440 In [70]: i.fromstring(s) In [71]: len i.tostring() -------> len(i.tostring()) Out[71]: 860 In [72]: len i.tostring().encode('string-escape') -------> len(i.tostring().encode('string-escape')) Out[72]: 3440 In [73]: 160*43 Out[73]: 6880 In [74]: g = g15daemon.g15screen(g15daemon.SCREEN_PIXEL) In [76]: g.set_buffer(i.tostring()) --------------------------------------------------------------------------- exceptions.Exception Traceback (most recent call last) /home/voidy/ /usr/lib/python2.4/site-packages/g15daemon.py in set_buffer(self, buf, use_exceptions) 121 def set_buffer(self, buf, use_exceptions=True): 122 """Set a new buffer""" --> 123 return self.__validate_buffer(buf,use_exceptions) 124 125 def set_pixel(self, x, y, pixel): /usr/lib/python2.4/site-packages/g15daemon.py in __validate_buffer(self, buf, use_exceptions) 95 if len(buf) != MAX_BUFFER_LENGTH: 96 if use_exceptions: ---> 97 raise Exception("Buffer has wrong size(%d)" % len(buf)) 98 return False 99 for i in range(0,MAX_BUFFER_LENGTH): Exception: Buffer has wrong size(860) Any help would be appreciated so much, i've been almost enraged with frustration at this. I just really want to be able to form my canvas with the graphical and textual methods from pil, and then convert it over to the lcd's scerenbuffer.. Regards, Tom/ From fredrik at pythonware.com Tue Nov 14 22:53:24 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 14 Nov 2006 22:53:24 +0100 Subject: [Image-SIG] Monochrome image tostring length problems In-Reply-To: <455A32F3.80109@t0mb.net> References: <455A32F3.80109@t0mb.net> Message-ID: tom wrote: > I'm having a real problem at the moment trying to figure out how to pass > strings of 1bit image data between PIL and the g15daemon which supports > the logitech g15 keyboards lcd. Basically, it's 160x143 in resolution. > The g15 python bindings have two methods of note. The > loader_10_ascii_format method loads a file which is formatted as > 1001101110001 etc, and converts it in to a string of the form > \x00\x01\x01\x00 etc.... this string has a len of 6880, which is the > length it should be, being 160x43. If i try to do anything with a PIL > created image initialised like > > i = Image.new('1', (160, 43)) > > and then, with s being the string returned from the g15 ascii loader, do > something like this > > i.fromstring(s) > > then you have a problem illustrated like so: > > len(i.tostring('raw', '1')) > returns 860 (6880 / 8) > > len(i.tostring('raw', '1').encode('string-escape') > returns 3440 half the number i need... > > I cannot send this string to the g15daemon.set_buffer method as it needs > to be a string which is 6880 in length try using i = Image.new('L', (160, 43)) instead. From michele.petrazzo at unipex.it Fri Nov 17 12:52:01 2006 From: michele.petrazzo at unipex.it (Michele Petrazzo) Date: Fri, 17 Nov 2006 12:52:01 +0100 Subject: [Image-SIG] separate TIFF In-Reply-To: <3190139.313691163491321617.JavaMail.defaultUser@defaultHost> References: <3190139.313691163491321617.JavaMail.defaultUser@defaultHost> Message-ID: <455DA261.6000701@unipex.it> sergiao at fastwebnet.it wrote: > Hi guys, i have a TIFF image of 10 pages, i have to make more file of > 2 pages with a python script, what i have to do? According to the PIL doc, you can't with PIL.For do this, you can use a lot of "platform specific" programs, like that on tiff tools, that are on all (more or less) the linux platforms or compiled by the gnuwin32 team by the win OS (tiffcp and tiffsplit are your friend). Or you can use FreeImagePy (freeimagepy.sf.net), that are a python lib that can help you do to it. you can do something like (with the last freeimagepy release 22): import FreeImagePy as FIPY fname = "test.tif" img = FIPY.Image(fname) def createImg(num): img = FIPY.Image() #The size here it not needed, because every bitmap page set its size img.new( multiBitmap="file%i.tiff" % num ) return img for num, bmp in enumerate( img ): if num % 2 == 0: #Create a new image myImg = createImg(num) #Append a new one myImg.appendPage( bitmap=bmp ) if num % 2 == 0: #Delete the first page, according with the freeimage doc myImg.deletePage(0) > > sorry for my bad english Ciao :), Michele From coen at reservoir.nl Fri Nov 17 17:41:20 2006 From: coen at reservoir.nl (Coen van der Kamp) Date: Fri, 17 Nov 2006 17:41:20 +0100 Subject: [Image-SIG] bezier curve Message-ID: <455DE630.4080905@reservoir.nl> I tried to draw a bezier curve. The code underneath generates a triangle and not the desired curved line... Am I missing something?! Coen. import Image, ImageDraw, ImagePath import aggdraw im = Image.new('RGB', (100, 100), 'white') draw = aggdraw.Draw(im) pen = aggdraw.Pen('black', width=5, opacity=255) mypath = aggdraw.Path() #Adds a bezier curve segment to the path mypath.rcurveto(10, 10, 90, 10, 90, 90) xy = (0,0) draw.path(xy, mypath, pen) draw.flush() im.save ('myfile.png', 'png') From tom.heathcote at petris.com Mon Nov 13 17:17:18 2006 From: tom.heathcote at petris.com (Tom Heathcote) Date: Mon, 13 Nov 2006 16:17:18 +0000 Subject: [Image-SIG] Fixes to PIL for handling XPM files. In-Reply-To: References: <453E2C2C.2040808@petris.com> Message-ID: <45589A8E.7030209@petris.com> Fredrik Lundh wrote: > >> *Fix:* Changed _save() in GifImagePlugin.py. The code was looking in >> the wrong dictionary for the transparency value. >> >> *Fix:* Changed _save() in PngImagePlugin.py. The code was looking in >> the wrong dictionary for the transparency value. >> > > the "info" dictionary is a free-form dictionary used to return in- > formation from plugin loaders. its content is not standardized, > is dropped by most image operations, and is therefore not used by "save". > > instead, you have to use an explicit option when saving an image: > > im.save(filename, transparency=value) > > (that you had to change all plugins should have told you that maybe you > weren't using the API in the intended way, don't you think? ;-) > > Yes... in retrospect it seems quite obvious :) I can only imagine that I was not quite on top form when I was doing this work... I will examine my code and submit a new patch with these incorrect changes removed. Sorry for the delay in replying. I tried to send this message to the list several times, and it was getting blocked because of some quirk in my company's mail server setup. It took me a while to notice that it finally got through. -- Tom Heathcote Petris Technology tom.heathcote at petris.com 154 Brent Street Tel +44 20 8202 2433 London NW4 2DR Fax +44 20 8202 2287 England -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20061113/5c38a809/attachment.html From blueblud at gmail.com Thu Nov 16 00:10:31 2006 From: blueblud at gmail.com (Sangwon Chae) Date: Wed, 15 Nov 2006 15:10:31 -0800 Subject: [Image-SIG] display image file from buffer Message-ID: <4fa88de40611151510y72e5c7a3q268eeb36872ea3d3@mail.gmail.com> Hello~ There are a server and client program using socket. The client is connected to a wireless camera and received frames(jpg format) from the camera. Then, the client sends it to the server. The server displays them if a frame is completed received. I'm using pygame for a display part. However, there is a problem. The packet includes a jpg foramt data and is stored into a buffer, so I should display them. When I've seen pygame.image module, there is a way to use a buffer to display such as pygame.image.frombuffer. But, I cannot use it because it supports raw data but not jpg file format. Do you have any idea to display buffer(jpg format) immediately? (not to store file and read it) Thanks. >* Arthur Elsenaar wrote: *>* *>>* what I like to do, is reading arbitrary images coming in over a socket *>>* and display them _as they arrive_, so when a chunk is in, immediatly *>>* display it (in pygame). *>>* From the PIL documentation, I can see that one needs to use the *>>* frombuffer() method and feed that to pygame using the fromstring() *>>* method. Also I understand the pygame.load() function needs a complete *>>* file like object (StringIO), so how does one go about partly *>>* displaying *>>* these incoming data chunks? Do I need to use the PIL parse function *>>* somehow? Do I need to pad the missing data? *>* *>* while PIL can decode things incrementally, there's no (reliable) way to *>* get access to incomplete image data. maybe in 1.1.6 ? * hmm, too bad PIL can't do this cleanly. But I'm still interested in what you mean by 'no reliable'. Can you tell a bit more on what -can- be done in this respect? As I'm working on an art project, less than perfect results aren't a problem. -- Sangwon Chae Ph.d student at Electrical Engineering and Computer Science, UCI 1-949-838-5342 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20061115/3e2561e9/attachment.htm From Colin.Brown at metservice.com Fri Nov 17 05:42:17 2006 From: Colin.Brown at metservice.com (Colin Brown) Date: Fri, 17 Nov 2006 16:42:17 +1200 Subject: [Image-SIG] Problem using PIL with cx_freeze Message-ID: <51165903AB2C4B4E8A648FF228AFB50E02DA5363@hurricrane.met.co.nz> Hello I am attempting to put together a package that uses python2.3 under the corresponding version of cx_freeze on Windows 2K. My test module is: import cStringIO, StringIO import Image import WmfPlugin def convert(wmfdata): im = Image.open(cStringIO.StringIO(wmfdata)) x,y = im.size smallest = min(x,y) scale = int(2*1728.0/smallest + 0.99) im.size = x*scale, y*scale im.load() if x > y: im = im.rotate(90) out = StringIO.StringIO() im.save(out,'PNG') return out.getvalue() if __name__ == '__main__': d1 = open('wind.wmf','rb').read() d2 = convert(d1) open('wind.png','wb').write(d2) When run interactively from python23 it works really well but when frozen I get the following error: Traceback (most recent call last): File "C:\Src\1_cx_Freeze-3.0.3\initscripts\console.py", line 27, in ? exec code in m.__dict__ File "wmf2png.py", line 30, in ? File "wmf2png.py", line 20, in convert If x > y: File "C:\Python23\lib\site-packages\PIL\Image.py", line 1295, in save Save_handler = SAVE[string.upper(format)] # unknown format KeyError: 'PNG' The traceback line numbers for some reason are not showing the correct error location in the module: => im.save(out,'PNG') I added debugging into Image.py to print out SAVE before the exception and find: {'WMF': } Running the unfrozen module interactively SAVE has entries for TIFF, PNG, GIF, WMF etc. The environment is a new Win2K + SP4 with the latest python2.3 code running under VMWare on an XP box. I have tried various ways of attempting to register the PNG module without success. Any thoughts as to how to get around this problem would be much appreciated. Thanks Colin Brown PyNZ Ps: 1. I am using 2.3 as there appears to be no later version of the WmfPlugin module. 2. Although there are other WMF converters available, the PIL module is one of the few that handles the in-house written WMF files I have to convert :-) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20061117/aecdb71a/attachment.html From fredrik at pythonware.com Mon Nov 20 17:42:38 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 20 Nov 2006 17:42:38 +0100 Subject: [Image-SIG] Problem using PIL with cx_freeze In-Reply-To: <51165903AB2C4B4E8A648FF228AFB50E02DA5363@hurricrane.met.co.nz> References: <51165903AB2C4B4E8A648FF228AFB50E02DA5363@hurricrane.met.co.nz> Message-ID: (repost; the original seems to have gotten stuck somewhere) Colin Brown wrote: > I am attempting to put together a package that uses python2.3 under the corresponding version of cx_freeze on Windows 2K. > When run interactively from python23 it works really well but when frozen I get the following error: > > Save_handler = SAVE[string.upper(format)] # unknown format > KeyError: 'PNG' PIL uses a dynamic mechanism to load plugins, and freeze tools sometimes forget to include the plugins PIL needs. the easiest way to solve this is to explicitly import the ones you need: import Image import PngImagePlugin import JpegImagePlugin # etc for more on this, see: http://www.py2exe.org/index.cgi/PIL_and_py2exe From Colin.Brown at metservice.com Tue Nov 21 03:06:18 2006 From: Colin.Brown at metservice.com (Colin Brown) Date: Tue, 21 Nov 2006 14:06:18 +1200 Subject: [Image-SIG] Problem using PIL with cx_freeze In-Reply-To: Message-ID: <51165903AB2C4B4E8A648FF228AFB50E02DA57C5@hurricrane.met.co.nz> Fredrik Lundh wrote: PIL uses a dynamic mechanism to load plugins, and freeze tools sometimes forget to include the plugins PIL needs. the easiest way to solve this is to explicitly import the ones you need: import Image import PngImagePlugin import JpegImagePlugin # etc for more on this, see: http://www.py2exe.org/index.cgi/PIL_and_py2exe ----------------------------------------------------------------- Thanks Fredrik, that helped me get the software to run after freezing. However I have one remaining inexplicable difference when I run the frozen software in two different VMWare environments. Environment 1: Win2K (SP4), python2.3.5, pywin32-210.win32-py2.3, PIL-1.1.5.win32-py2.3, pilwmf-1.0b2-20040224.win32-py2.3 and cx_Freeze-3.0.3-win32-py23. Environemnt 2: Win2K (SP4). I have built and frozen the image in environment 1 and then copied the frozen software across to environment 2. When I run the program two different PNG images are created? The image is a chart product which has coastal outlines, various symbols, labels and latitude/longitude grids as a series of points. Upon visual examination the Env2 image is the same as the Env1 image except for the lat/long grid "points" (small solid dots). I suspect that there is something else from within the PIL library that it is using. I ran the unfrozen code interactively in Env1 with the "-v" command line option to see what modules are called. I have included all the dynamically-loaded .pyd modules into the freeze output directory and imported all those within PIL that are mentioned; as follows: import Image import WmfPlugin import PngImagePlugin, ImagePalette, ImageFile import BmpImagePlugin, GifImagePlugin, JpegImagePlugin import PpmImagePlugin, TiffImagePlugin Previously I had tried "from PIL import *" but that did not seem to help. Any further thoughts on what is missing would be appreciated. Thanks Colin Brown PyNZ From zpincus at stanford.edu Wed Nov 29 10:10:45 2006 From: zpincus at stanford.edu (Zachary Pincus) Date: Wed, 29 Nov 2006 01:10:45 -0800 Subject: [Image-SIG] Patch: Read/write big-endian 16-bit TIFF data properly Message-ID: Hello all, I've found and fixed a minor problem in PIL's TIFF handling. SUMMARY: PIL does not read 16-bit TIFF files correctly if they are in big-endian byte order. A patch to fix this is included. MORE DETAIL: 16-bit grayscale TIFF files are a (very) common scientific imaging format. Unfortunately, PIL does not read these files gracefully. Specifically, while PIL's TiffImagePlugin can properly read big- and little-endian TIFF tag directories, the plugin does not pass on information about the endian-ness of the file to the decoder, so the actual image bytes are read incorrectly. Attached is a patch to fix this problem. The patch keys the image mode and raw mode on the endian-ness of the input file, as well as the rest of the TIFF tags, so that these modes are properly passed to the decoder. Additionally, the patch allows for proper writing of big- endian tiff files. Also attached are two 2x2 16-bit TIFF images, with all pixels having value 256. One image is little-endian and the other big-endian. Here's a test case for the behavior, with these images: Current PIL 1.1.6b2: In [1]: import Image In [2]: im = Image.open('BigEndian.tif') In [3]: im.getpixel((0,0)) Out[3]: 1 In [4]: im = Image.open('LittleEndian.tif') In [5]: im.getpixel((0,0)) Out[5]: 256 Patched PIL 1.1.6b2: In [1]: import Image In [2]: im = Image.open('BigEndian.tif') In [3]: im.getpixel((0,0)) Out[3]: 256 In [4]: im = Image.open('LittleEndian.tif') In [5]: im.getpixel((0,0)) Out[5]: 256 Zach Pincus Program in Biomedical Informatics and Department of Biochemistry Stanford University School of Medicine -------------- next part -------------- A non-text attachment was scrubbed... Name: tiff-endian.patch Type: application/octet-stream Size: 8850 bytes Desc: not available Url : http://mail.python.org/pipermail/image-sig/attachments/20061129/b2fd916c/attachment.obj -------------- next part -------------- A non-text attachment was scrubbed... Name: BigEndian.tif Type: image/tiff Size: 118 bytes Desc: not available Url : http://mail.python.org/pipermail/image-sig/attachments/20061129/b2fd916c/attachment.tif -------------- next part -------------- A non-text attachment was scrubbed... Name: LittleEndian.tif Type: image/tiff Size: 118 bytes Desc: not available Url : http://mail.python.org/pipermail/image-sig/attachments/20061129/b2fd916c/attachment-0001.tif -------------- next part -------------- From cameron.walsh at gmail.com Thu Nov 30 03:00:27 2006 From: cameron.walsh at gmail.com (Cameron Walsh) Date: Thu, 30 Nov 2006 10:00:27 +0800 Subject: [Image-SIG] PIL throws exception when reading 8bit greyscale bitmap and pnm data Message-ID: <106309950611291800l19f38fd7s77001d6ff71e62c@mail.gmail.com> Hi all, I'm trying to extract the data from a bitmap or .pnm file using the following code: import Image img = Image.open("test.bmp","r") data=img.getdata() Unfortunately I get the following exception on Linux, but not on Windows: >>> data=img.getdata() Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.5/site-packages/PIL/Image.py", line 796, in getdata self.load() File "/usr/local/lib/python2.5/site-packages/PIL/ImageFile.py", line 147, in load self.map = mmap.mmap(file.fileno(), size) EnvironmentError: [Errno 19] No such device At this time, I cannot provide the full bitmap for copyright reasons, but I can provide some information about the bitmap: cameron at cameron-laptop:~$ file test.bmp test.bmp: PC bitmap data, Windows 3.x format, 1000 x 1000 x 8 The same code works for .ppm images in the same folder: cameron at cameron-laptop:~$ convert test.bmp test.ppm cameron at cameron-laptop:~$ python import Image img=Image.open("test.ppm") data=img.getdata() But does not work for .pnm images in the same folder: cameron at cameron-laptop:~$ convert test.bmp test.pnm cameron at cameron-laptop:~$ python import Image img=Image.open("test.pnm") data=img.getdata() Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.5/site-packages/PIL/Image.py", line 796, in getdata self.load() File "/usr/local/lib/python2.5/site-packages/PIL/ImageFile.py", line 147, in load self.map = mmap.mmap(file.fileno(), size) EnvironmentError: [Errno 19] No such device PIL Version on Linux and Windows: $Id: Image.py 2337 2005-03-25 07:50:30Z fredrik $ How can I avoid this error without converting each image into a different format? Is there any more information required? Thanks and regards, Cameron. From zpincus at stanford.edu Thu Nov 30 03:51:50 2006 From: zpincus at stanford.edu (Zachary Pincus) Date: Wed, 29 Nov 2006 18:51:50 -0800 Subject: [Image-SIG] PIL and 16-bit image types -- an offer of help Message-ID: <8C3115E9-D509-4A1F-A57C-9D6F302229AA@stanford.edu> Hello folks, SUMMARY: I am offering to implement fixes in PIL to make its handling of 16- bit image types less vexing. Are the PIL maintainers interested in such help? I have a few questions to ask, and then I could get to work if some maintainer would give me a preliminary go-ahead. THE FULL STORY: I'm trying to use PIL for a scientific imaging library. Unfortunately, many of the images I need to deal with are 16-bit grayscale image files; an image mode that PIL does not deal well with. Thus I will need to either write work-arounds in my code to fix the problems, or fix PIL itself. I would prefer to do the latter. I previously sent a patch to this list to allow for proper reading of 16-bit TIFF files; however this patch is a very simple-minded and I think that with a few more changes, PIL could support 16-bit grayscale files in a much better way. However there's a major philosophical issue that needs to be addressed first! Specifically, does mode 'I;16' mean '16-bit little-endian integers' or '16-bit native integers'? In practice the code uses the former definition; however, Imaging.h declares the latter to be the case. The real issue is that all other multi-byte types like 'I' and 'F' are stored as native byte order in memory, regardless of how they are read in. Thus, both users and developers are abstracted from the question of byte ordering. (Except that developers still need to care about endian-ness at serialization time.) However, 16-bit image types are not so insulated, which is what makes them so vexing in PIL. This makes double the work for trying to add 16-bit compatibility to any image function, because you have to write the compatibility twice, once for each endian-ness. Also, writing a function to deal with a particular byte ordering which may or may not be native is both error-prone and inefficient. The real problem is just one of nomenclature. Pack.c and Unpack.c make a distinction between 'raw modes' like 'I;32' (which implicitly means 32-bit little-endian) and normal use-level 'modes' like 'I' (which means 32-bit native endian). However, the use of 'I;16' as a user-level image mode has clouded issues, because even at the user level it means 'little endian'. These subtle differences in meaning cause a lot of the 16-bit manipulation bugs that I've seen in PIL so far. I think that Imaging.h is correct in that 'I;16' ought to be treated as native byte order when it is used as an image mode (just like 'I' is). However, as a raw mode, 'I;16' needs to mean 'little-endian' just as 'I;32' means 'little endian'. This change wouldn't be too hard to make, and it would be (mostly) backwards compatible. However, having one name for two different entities (a 'mode' with native order and a 'raw mode' with little-endian order) is likely to be very confusing and the source of future bugs. It seems like the better solution would be to add a new '16-bit unsigned native byte order' image type to PIL -- maybe 'S' for 'short' -- and reserve 'I; 16' and 'I;16B' strictly for raw modes. The only problem would be that this would break some older code that relied on these 'experimental' features. Is anyone interested in discussing these options (and several other bugs in PIL's image packing and unpacking that I've discovered in looking at the code)? I'm happy to take this on, since these are changes I need to make anyway for my project and I'd rather see them in the PIL trunk than in my own fork. Thanks, Zach Pincus Program in Biomedical Informatics and Department of Biochemistry Stanford University School of Medicine From bhartsho at yahoo.com Wed Nov 29 09:43:29 2006 From: bhartsho at yahoo.com (Hart's Antler) Date: Wed, 29 Nov 2006 00:43:29 -0800 (PST) Subject: [Image-SIG] GIF89a for PIL1.1.6? Message-ID: <780363.11603.qm@web34506.mail.mud.yahoo.com> Hi PIL users, just wanted to say more complete animated GIF support for PIL would be a great thing, there are at least a few others who could also use it: http://www.somethinkodd.com/oddthinking/2005/12/06/python-imaging-library-pil-and-animated-gifs/ Current GIF87a can't do looping or frame delay. -brett ____________________________________________________________________________________ Do you Yahoo!? Everyone is raving about the all-new Yahoo! Mail beta. http://new.mail.yahoo.com