From fredrik at pythonware.com Mon Oct 2 12:40:25 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 2 Oct 2006 12:40:25 +0200 Subject: [Image-SIG] Drawing filled polygons with holes with aggdraw References: <89681a450609291550x56b3d43ch40c9ee0f894ba254@mail.gmail.com> Message-ID: "Jir? Mikul?sek" wrote: > I would like to ask whether it is possible to draw properly filled multipolygons > with aggdraw. By properly filled I mean that when I have for example > multipolygon consisting of two polygons where one is inside another - > some call these objects polygons with holes - and want to draw it with > solid fill, then I would like to have filled only the space between > them. you should be able to create Path objects: http://effbot.org/zone/pythondoc-aggdraw.htm#aggdraw.Path-class and draw them using the "path" method, but that code is experimental and may be buggy. From cspence at sarnoff.com Tue Oct 3 16:17:33 2006 From: cspence at sarnoff.com (CLAY SPENCE) Date: Tue, 03 Oct 2006 10:17:33 -0400 Subject: [Image-SIG] Freezing with PIL Message-ID: <452270FD.5090708@sarnoff.com> Hi, I am trying to freeze a program that uses the Image module under Windows, using visual studio .net 7.1. I'm having a problem that seems to be a failure to find some module/library/.pyd/.lib file(s). When I run the resulting executable, it raises an IOError in Image.open, saying "Cannot identify image file." My program sets sys.path, rather than appending to it, so I can distribute all necessary libraries with the executable. This is suggested in the freeze documentation. If I change the code to append to sys.path instead, everything runs fine. So, I assume there is some library or module that it can't find without the standard sys.path, but doesn't complain about not finding. How do I find out what's missing? I didn't find an answer in the freeze or PIL documentation (which doesn't prove it isn't there). More detail, in case it matters: When I run "python \Tools\freeze\freeze.py program.py", early on it prints a path for _imaging.pyd, but near the end it complains with the message "No definition of module _imaging in any specified map file." I gather this is some set of compiler parameters I need to give to freeze. Freeze gives the same complaint for a few other modules. It also says "Warning: unknown modules remain: _imaging ..." I understand this means I need to distribute the .pyd (and .lib?) files with the executable. I set sys.path to point into a lib directory containing those .pyd and .lib files that I can identify, including _imaging.pyd. Indulging in wishful thinking, it seems to build Ok after this with nmake. Clay From fredrik at pythonware.com Tue Oct 3 21:30:04 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 03 Oct 2006 21:30:04 +0200 Subject: [Image-SIG] Freezing with PIL In-Reply-To: <452270FD.5090708@sarnoff.com> References: <452270FD.5090708@sarnoff.com> Message-ID: CLAY SPENCE wrote: > I am trying to freeze a program that uses the Image module under > Windows, using visual studio .net 7.1. I'm having a problem that seems > to be a failure to find some module/library/.pyd/.lib file(s). > > When I run the resulting executable, it raises an IOError in Image.open, > saying "Cannot identify image file." My program sets sys.path, rather > than appending to it, so I can distribute all necessary libraries with > the executable. This is suggested in the freeze documentation. If I > change the code to append to sys.path instead, everything runs fine. So, > I assume there is some library or module that it can't find without the > standard sys.path, but doesn't complain about not finding. How do I find > out what's missing? I didn't find an answer in the freeze or PIL > documentation (which doesn't prove it isn't there). see the "Solution" section on this page for a solution: http://www.py2exe.org/index.cgi/PIL_and_py2exe From cspence at sarnoff.com Tue Oct 3 22:40:01 2006 From: cspence at sarnoff.com (CLAY SPENCE) Date: Tue, 03 Oct 2006 16:40:01 -0400 Subject: [Image-SIG] Freezing with PIL Message-ID: <4522CAA1.2040804@sarnoff.com> For what its worth, I think I fixed it. It seemed to be a freeze problem, not finding all of the modules. I copied knee.py from Python-*/Demo/imputil, modified it to print the names of successfully imported modules, and then froze versions of my program with the normal sys.path and with this replaced. I then looked for modules that weren't imported in the version that fails. The image file format plugins were missing, like PngImagePlugin. I put an explicit import statement for these into the main program file, and freeze now includes them. There is slightly odd python code for importing them in Image.py, and this hides them from freeze. Clay -------------- next part -------------- An embedded message was scrubbed... From: Clay Spence Subject: Freezing with PIL Date: Tue, 03 Oct 2006 10:17:33 -0400 Size: 1957 Url: http://mail.python.org/pipermail/image-sig/attachments/20061003/6b5d53e3/attachment.mht From cspence at sarnoff.com Wed Oct 4 15:12:49 2006 From: cspence at sarnoff.com (CLAY SPENCE) Date: Wed, 04 Oct 2006 09:12:49 -0400 Subject: [Image-SIG] Freezing with PIL In-Reply-To: References: Message-ID: <4523B351.6000508@sarnoff.com> Thanks, Fred. That confirms what I found. After importing the image plugins, that page suggests executing "Image._initialized=2". My code seems to work without it. Is it a good idea anyway? Clay Fredrik Lundh wrote: > see the "Solution" section on this page for a solution: > > http://www.py2exe.org/index.cgi/PIL_and_py2exe > > From fredrik at pythonware.com Wed Oct 4 16:08:26 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 4 Oct 2006 16:08:26 +0200 Subject: [Image-SIG] Freezing with PIL References: <4523B351.6000508@sarnoff.com> Message-ID: "CLAY SPENCE" wrote: > After importing the image plugins, that page suggests executing > "Image._initialized=2". My code seems to work without it. Is it a good > idea anyway? by default, Image.open scans the path for additional image plugins the first time it fails to open a file using the plugins that has already been imported. the above assignment simply disables this scan. From fredrik at pythonware.com Sat Oct 7 11:12:27 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 07 Oct 2006 11:12:27 +0200 Subject: [Image-SIG] frombuffer defaults to flip of fromstring? In-Reply-To: References: Message-ID: > Dan Torop wrote: > >> I was curious whether there was a bug in the default behavior of >> Image.frombuffer(). > > sure looks like a bug. > > http://effbot.python-hosting.com/ticket/54 This is a stupid bug (*), but I'm not sure if I can just fix this without breaking deployed code. My current idea is to 1) issue a warning if "frombuffer" is called with default arguments, and 2) fix the documentation to mention the bug and how to work around it in a backward- *and* forward-compatible way. Opinions? *) PIL's extended test suite does careful tests on "frombuffer", comparing the output to that of "fromstring", but I clearly forgot to include the default argument case in those test :-( From fredrik at pythonware.com Sat Oct 7 18:25:28 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 07 Oct 2006 18:25:28 +0200 Subject: [Image-SIG] ANN: PIL 1.1.6 beta 2 (october 7, 2006) Message-ID: A little later that planned, but PIL 1.1.6 beta 2 is now available from SVN: http://svn.effbot.python-hosting.com/tags/pil-1.1.6b2/ A tarball will appear on effbot.org shortly: http://effbot.org/downloads/#Imaging As usual, PIL 1.1.6 supports all Python versions from 1.5.2 and onwards, including 2.5. For a hopefully complete list of changes, see: http://effbot.org/zone/pil-changes-116.htm Report bugs to this list. (bugs in the alpha/beta releases can also be reported directly to me, if you prefer) enjoy! /F From fredrik at pythonware.com Sat Oct 7 20:02:59 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 07 Oct 2006 20:02:59 +0200 Subject: [Image-SIG] ANN: PIL 1.1.6 beta 2 (october 7, 2006) In-Reply-To: References: Message-ID: <4527EBD3.80102@pythonware.com> > A tarball will appear on effbot.org shortly: > > http://effbot.org/downloads/#Imaging windows binaries for 2.4 and 2.5 are now available as well. From fredrik at pythonware.com Sat Oct 7 20:03:11 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 07 Oct 2006 20:03:11 +0200 Subject: [Image-SIG] ANN: PIL 1.1.6 beta 2 (october 7, 2006) In-Reply-To: References: Message-ID: > A tarball will appear on effbot.org shortly: > > http://effbot.org/downloads/#Imaging windows binaries for 2.4 and 2.5 are now available as well. From thomir at gmail.com Tue Oct 10 01:35:06 2006 From: thomir at gmail.com (Thomi Richards) Date: Tue, 10 Oct 2006 12:35:06 +1300 Subject: [Image-SIG] problems setting DPI in TIFF files Message-ID: <631b002c0610091635k5c796c8dp2cf74ecdb903152d@mail.gmail.com> Hello, I'm generating some TIFF files using the PIL. These files then get sent to another applicaion which prints them. I have been told that there is a field in TIFF files which sets the image resolution. The documentation for 1.1.5states that: " The *open* method sets the following *info* properties: *compression* Compression mode. *dpi* (1.1.5) Image resolution as an (xdpi, ydpi) tuple, where applicable. You can use the *tag* attribute to get more detailed information about the image resolution. "I downloaded and cmpiled 1.1.5, but these attributes do not show up. Here's an example: >>> import Image >>> im = Image.open('Bishop_Bob.tiff') >>> im.dpi Traceback (most recent call last): File "", line 1, in ? AttributeError: TiffImageFile instance has no attribute 'dpi' I tried using the "im.tag" attribute, but I cannot work out what tag number I should be looking at. In any case, none of the tags present contain the value of 72, which seems to be the default resolution of the image. I hope someone out there can help, I've been trying to crack this problem for a few days now. Thanks, -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20061010/377f0f65/attachment.htm From fredrik at pythonware.com Tue Oct 10 14:24:11 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 10 Oct 2006 14:24:11 +0200 Subject: [Image-SIG] problems setting DPI in TIFF files References: <631b002c0610091635k5c796c8dp2cf74ecdb903152d@mail.gmail.com> Message-ID: Thomi Richards wrote: > I'm generating some TIFF files using the PIL. These files then get sent to > another applicaion which prints them. I have been told that there is a field > in TIFF files which sets the image resolution. The documentation for > 1.1.5 states that: > > The *open* method sets the following *info* properties: info-properties are stored in the info dictionary, not as plain attributes on the image object. this should work better: >>> im = Image.open(...) >>> im.info["dpi"] From david at laserfilm.net Fri Oct 13 14:28:52 2006 From: david at laserfilm.net (David (Laserfilm)) Date: Fri, 13 Oct 2006 14:28:52 +0200 Subject: [Image-SIG] Converting BMP -> PNG + transparency Message-ID: <000201c6eec3$29773730$4d001aac@programador> Hello, Oli. I have a similar problem. I need to save a picturebox or convert a bmp file to png with transparent background. I have a lot of problems with the GDI+, and now I'm lost. Can you help me with this? Regards, David. From kelvin.chu at uvm.edu Fri Oct 13 23:36:43 2006 From: kelvin.chu at uvm.edu (Kelvin Chu) Date: Fri, 13 Oct 2006 17:36:43 -0400 Subject: [Image-SIG] Altering an Image Sequence. Message-ID: Hi there; I'm trying to subtract a background from a TIF image sequence. I can use the ImageSequence module to iterate over the frames of a sequence, but I can't seem to figure out how to perform an operation on a specific frame and write that frame back into the sequence. Is it possible to write to a specific frame in an image sequence and then write the sequence to a file? Thanks very much for any light you can shed on this problem. Best, Kelvin Chu -- Kelvin Chu, Physics Department, Cook Building 82 University Place, University of Vermont, Burlington, VT 05405-0125 http://www.uvm.edu/~kchu/; (802) 656-0064; Fax: (802) 656-0817 From Geoff at teammsa.com Sun Oct 15 02:46:16 2006 From: Geoff at teammsa.com (Geoff Skerrett) Date: Sat, 14 Oct 2006 21:46:16 -0300 Subject: [Image-SIG] PIL 1.1.6 TIFF and Group3/4 Compression Message-ID: <7AE213A7B281E142A73F8180E60B6A310825D0@meeka.teammsa.local> With the upcoming release of PIL 1.1.6, I was wondering if the group3 and group4 compression would be implemented. ... or is that more a "not in this life time" issue ? About to start on a new project and would like to use PIL if possible, and expect to work with alot of TIFF files. Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20061014/9a4da468/attachment.html From ewbc at pennsylvania-blue.navy.mil Tue Oct 17 22:36:32 2006 From: ewbc at pennsylvania-blue.navy.mil (Bill Gonzalez) Date: Tue, 17 Oct 2006 22:36:32 +0200 Subject: [Image-SIG] striptease Message-ID: <45353ED0.2070801@pennsylvania-blue.navy.mil> An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20061017/4c279a4d/attachment.htm -------------- next part -------------- A non-text attachment was scrubbed... Name: impertinent.gif Type: image/gif Size: 12629 bytes Desc: not available Url : http://mail.python.org/pipermail/image-sig/attachments/20061017/4c279a4d/attachment.gif From dlxyqa at bibb.co.uk Thu Oct 19 02:20:56 2006 From: dlxyqa at bibb.co.uk (Clement Christian) Date: Wed, 18 Oct 2006 20:20:56 -0400 Subject: [Image-SIG] comfortable Styrofoam Message-ID: <4536C4E8.8070204@anycolorinc.com> An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20061018/03147a24/attachment.html -------------- next part -------------- A non-text attachment was scrubbed... Name: quotable.gif Type: image/gif Size: 7769 bytes Desc: not available Url : http://mail.python.org/pipermail/image-sig/attachments/20061018/03147a24/attachment.gif From wulabs at gmail.com Sun Oct 22 22:13:26 2006 From: wulabs at gmail.com (Jack Wu) Date: Sun, 22 Oct 2006 13:13:26 -0700 Subject: [Image-SIG] How to save a GIF image with the same color palette as it was opened Message-ID: <234081550610221313n6526a817wcbd9d8814a33eaa4@mail.gmail.com> Hi I am having a problem where the GIF images are not saving with the same color palette as the original GIF image. I am performing resizing functions on a passed in GIF image. The output I get now is a pixelated image that has a generic color palette rather than the original palette. Does anyone know how to fix this? -- Jack Wu From fredrik at pythonware.com Sun Oct 22 23:27:24 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 22 Oct 2006 23:27:24 +0200 Subject: [Image-SIG] How to save a GIF image with the same color palette as it was opened In-Reply-To: <234081550610221313n6526a817wcbd9d8814a33eaa4@mail.gmail.com> References: <234081550610221313n6526a817wcbd9d8814a33eaa4@mail.gmail.com> Message-ID: Jack Wu wrote: > I am having a problem where the GIF images are not saving with the > same color palette as the original GIF image. > > I am performing resizing functions on a passed in GIF image. The > output I get now is a pixelated image that has a generic color palette > rather than the original palette. if the output is "pixelated" and "generic", it sounds like you're doing more than just a plain resize... From ajkadri at googlemail.com Sat Oct 21 14:53:14 2006 From: ajkadri at googlemail.com (Asrarahmed Kadri) Date: Sat, 21 Oct 2006 13:53:14 +0100 Subject: [Image-SIG] Beginner question Message-ID: Hi, I am a new member of this group. I am interested in drawing graphs and polygons using PIL. Is it possible to do so?? If yes, then where can I find some tutorials to get me going on this track?? Thanks. regards, Asrarahmed -- To HIM you shall return. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20061021/6be96e53/attachment.html From gscott2112 at gmail.com Wed Oct 18 18:22:44 2006 From: gscott2112 at gmail.com (Gordon Scott) Date: Wed, 18 Oct 2006 09:22:44 -0700 Subject: [Image-SIG] Converting to GIF images? Message-ID: <8c856b690610180922r1f741ff1y7e38446934443961@mail.gmail.com> I'm trying to use PIL to convert some images to GIF and am having the same problem as everyone else seems to have. When converting images from other formats into GIF, the result is rather low quality. After googling and searching the list archives I've seen a few people mention the same problem and that it has to do something with the default palette for PIL uses for GIF images? Does anyone have a work around or solution for generating better quality GIFs? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20061018/c3e1b057/attachment.htm From fredrik at pythonware.com Mon Oct 23 23:06:04 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 23 Oct 2006 23:06:04 +0200 Subject: [Image-SIG] Beginner question In-Reply-To: References: Message-ID: Asrarahmed Kadri wrote: > I am a new member of this group. I am interested in drawing graphs and > polygons using PIL. > Is it possible to do so?? > > If yes, then where can I find some tutorials to get me going on this track?? the PIL handbook might be a good place to start: http://www.pythonware.com/library/pil/handbook/index.htm especially http://www.pythonware.com/library/pil/handbook/imagedraw.htm From fredrik at pythonware.com Mon Oct 23 23:10:18 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 23 Oct 2006 23:10:18 +0200 Subject: [Image-SIG] Converting to GIF images? In-Reply-To: <8c856b690610180922r1f741ff1y7e38446934443961@mail.gmail.com> References: <8c856b690610180922r1f741ff1y7e38446934443961@mail.gmail.com> Message-ID: Gordon Scott wrote: > I'm trying to use PIL to convert some images to GIF and am having the > same problem as everyone else seems to have. > When converting images from other formats into GIF, the result is rather > low quality. GIF is an utterly crappy format; low quality comes with the territory. any reason you cannot use PNG instead? > After googling and searching the list archives I've seen a few people > mention the same problem and that it has to do something with the > default palette for PIL uses for GIF images? it's more often the dithering that's done when you convert RGB images (which can contain millions of distinct colors) to GIF (which can con- tain 256 colors at the most). you can disable dithering by explicitly converting the image before you save it: im = im.convert("P", dither=False) im.save("out.gif") From angelol at easyconnect.fr Tue Oct 24 16:59:09 2006 From: angelol at easyconnect.fr (Angelo) Date: Tue, 24 Oct 2006 16:59:09 +0200 Subject: [Image-SIG] I don't understand this warning Message-ID: <1161701949.18832.18.camel@localhost> Hello, My PIL version is 1.1.5 . I have a small problem with this part of code : ... imageADFBV=Image.open('mon_image.jpg') widthADFBV, heightADFBV=imageADFBV.size ... # On sauvegarde l'image avant anti-aliasing imgDecoupADFBV=Image.new('RGBA', (widthADFBV, heightADFBV)) imgDecoupADFBV.putdata(newimageRGBA_ADFBV) ... # Creation d'une nouvelle image et integration des donnees recoltees . imgantialiasADFBV=Image.new('RGBA', (widthADFBV, heightADFBV)) imgantialiasADFBV.putdata(Antialiasing_ADFBV) a1_ADFBV, a2_ADFBV, a3_ADFBV, a4_ADFBV=imgantialiasADFBV.split() img_ADFBV=Image.merge('RGBA', (a1_ADFBV, a2_ADFBV, a3_ADFBV, a4_ADFBV)) # Sauvegarde de la nouvelle image (image tampon) img_ADFBV.save('decoupe_fond_ADFBV_tampon_0.png') ... the script make his job, but it returns me this warning : /usr/lib/python2.4/site-packages/PIL/Image.py:1120: DeprecationWarning: integer argument expected, got float self.im.putdata(data, scale, offset) What is the problem ? . Can you help me ? . a+ From fredrik at pythonware.com Tue Oct 24 17:20:46 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 24 Oct 2006 17:20:46 +0200 Subject: [Image-SIG] I don't understand this warning In-Reply-To: <1161701949.18832.18.camel@localhost> References: <1161701949.18832.18.camel@localhost> Message-ID: Angelo wrote: > # On sauvegarde l'image avant anti-aliasing > imgDecoupADFBV=Image.new('RGBA', (widthADFBV, heightADFBV)) > imgDecoupADFBV.putdata(newimageRGBA_ADFBV) > > the script make his job, but it returns me this warning : > > /usr/lib/python2.4/site-packages/PIL/Image.py:1120: DeprecationWarning: > integer argument expected, got float > self.im.putdata(data, scale, offset) does "newimageRGBA_ADFBV" perhaps contain floating point values? > What is the problem ? just an internal Python API that's a bit pickier than it has to be. you can safely ignore this warning. (for instructions on how to disable it, see the documentation for Python's "warnings" module). From angelol at easyconnect.fr Tue Oct 24 19:34:02 2006 From: angelol at easyconnect.fr (Angelo) Date: Tue, 24 Oct 2006 19:34:02 +0200 Subject: [Image-SIG] I don't understand this warning In-Reply-To: References: <1161701949.18832.18.camel@localhost> Message-ID: <1161711242.18832.35.camel@localhost> On mar, 2006-10-24 at 17:20 +0200, Fredrik Lundh wrote: > does "newimageRGBA_ADFBV" perhaps contain floating point values? In fact there was indeed a problem with floating point values in a list in another part of the script (the problem was in the Antialiasing_ADFBV list). This is good now, without warnings . Thanks a lot Fredrik . > just an internal Python API that's a bit pickier than it has to be. you > can safely ignore this warning. > > (for instructions on how to disable it, see the documentation for > Python's "warnings" module). a+ From tom.heathcote at petris.com Tue Oct 24 17:07:24 2006 From: tom.heathcote at petris.com (Tom Heathcote) Date: Tue, 24 Oct 2006 16:07:24 +0100 Subject: [Image-SIG] Fixes to PIL for handling XPM files. Message-ID: <453E2C2C.2040808@petris.com> I recently downloaded the Python Imaging Library (PIL 1.1.5), and I have been trying to use it to convert several hundred XPM files into GIFs (I also tried converting into PNGs which may be useful in the future). During this process, I ran into various problems which appear to be caused by bugs. Most of the difficulties were related to XPMs -- not being able to load XPM files which other applications were quite happy with. But there were also a couple of minor issues with transparency in GIF and PNG formats. Attached is a diff file containing the changes I had to make to the code to fix these problems. This fixes things for the vast majority of the XPM files I have. There are still some XPMs that can't be loaded (those which use more than one character per pixel for example), but these are far less common. Because I am not a regular contributer to this project I thought I should include more information than just the diffs, so here is a list of the bugs I found and what I changed as a result: *Bug:* PIL could not open some XPM files because it failed to cope with some features of XPM syntax. *Fix: * Various changes in XpmImagePlugin.py: * Changed the RE used to match the image header to one that copes with leading spaces and multiple spaces between words. * In XpmImageFile._open(), when reading the image palette: * Ignore lines which are commented-out. * Strip leading and trailing whitespace before processing. * Remove case sensitivity when looking for "None". * Use ImageColor.getrgb() to interpret color values. * Look ahead to detect colour names consisting of multiple words * In XpmImageFile.load_read() (when reading the pixels) ignore lines which are commented-out. *Bug: *PIL could not open some XPM files, because the color names were not recognized. *Fix: *various changes to ImageColor.py: * Changed the colormap to the standard list of X11 colours (as found on any Unix or Linux system). *Note*: before this change, the colormap apparently contained colours taken from CSS3 -- the comment reads 'X11 colour table (from "CSS3 module: Color working draft")'. However some of the standard X11 colours clashed with existing colours in the map. In the end, I removed all the CSS3 colours and just included the X11 colours. The comment does say "X11 colour table" after all. * getrgb(): Remove spaces from the color name in order to find a match. X11 has variations of some color names, such as "light blue" and "LightBlue". But the version with spaces was not recognized. * getrgb(): Recognize colours specified as a 48-bit RGB string (e.g. #FFFF0000AAAA). These are sometimes encountered in XPMs. The 3 bytes of extra precision are ignored, and the returned RGB value is a standard 24-bit RGB tuple. *Bug:* PIL loaded all XPM files incorrectly, shifting the entire image several pixels to the right (truncating it on the right, and adding a a band of incorrect pixels on the left). This is caused by trying to use memory mapping to read the file, which prevents the proper XPM decoder from being used. Memory mapping does not work because of the structure of XPM files -- the file includes characters (such as the opening and closing quotes on each line) which do not correspond to pixel values. *Fix:* Changed load() in ImageFile.py to explicitly exclude XPM files from the memory mapping. There may be a more elegent way to do this, perhaps by changing the value of ImageFile.tile for XPMs. But I tried the obvious thing -- changing the "raw" designation to something else, and that seemed to break things even more. Perhaps someone more familiar with this code could do better. *Bug:* Could not write GIFs with transparency. The pixels which should have been transparent were not. *Fix:* Changed _save() in GifImagePlugin.py. The code was looking in the wrong dictionary for the transparency value. * Bug:* Could not write PNGs with transparency. The pixels which should have been transparent were not. *Fix:* Changed _save() in PngImagePlugin.py. The code was looking in the wrong dictionary for the transparency value. -- Tom Heathcote -- 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/20061024/257bf27f/attachment-0001.htm -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: changes.diff Url: http://mail.python.org/pipermail/image-sig/attachments/20061024/257bf27f/attachment-0001.diff From fredrik at pythonware.com Thu Oct 26 10:23:39 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 26 Oct 2006 10:23:39 +0200 Subject: [Image-SIG] Fixes to PIL for handling XPM files. In-Reply-To: <453E2C2C.2040808@petris.com> References: <453E2C2C.2040808@petris.com> Message-ID: Tom Heathcote wrote: > Attached is a diff file containing the changes I had to make to the > code to fix these problems. This fixes things for the vast majority > of the XPM files I have. thanks. no time to comment on all these right now, but I couldn't help noticing the following: > *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? ;-) cheers /F From cjones2 at bigpond.net.au Fri Oct 27 01:01:15 2006 From: cjones2 at bigpond.net.au (Christopher Jones) Date: Fri, 27 Oct 2006 09:01:15 +1000 Subject: [Image-SIG] PIL QUAD transform Message-ID: <003101c6f952$a3fd5180$0301a8c0@orange> I have just discovered that the QUAD transform is not perspective: it does not preserve straight lines in the original image. Any way of doing a perspective transformation? Chris Jones From fredrik at pythonware.com Fri Oct 27 08:21:42 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 27 Oct 2006 08:21:42 +0200 Subject: [Image-SIG] PIL QUAD transform In-Reply-To: <003101c6f952$a3fd5180$0301a8c0@orange> References: <003101c6f952$a3fd5180$0301a8c0@orange> Message-ID: Christopher Jones wrote: > I have just discovered that the QUAD transform is not perspective: it does > not preserve straight lines in the original image. Any way of doing a > perspective transformation? in 1.1.5 and later, transform can take a PERSPECTIVE transform matrix, but I cannot seem to find any documentation on how the matrix data should look. checking the mailing list archives or the source is your best bet. From feihu_roger at yahoo.com.cn Fri Oct 27 11:28:16 2006 From: feihu_roger at yahoo.com.cn (feihu_roger) Date: Fri, 27 Oct 2006 17:28:16 +0800 Subject: [Image-SIG] some trouble about jpeg encode in PIL Message-ID: <20061027172424.876A.FEIHU_ROGER@yahoo.com.cn> I use PIL to thumbnail and save one jpeg. raise one IOException: >>> im= Image.open('e:/11.jpg') >>> im.thumbnail((600,600)) >>> im.save('e:/11_m.jpg', 'JPEG', quality=90,progressive=1) Traceback (most recent call last): File "", line 1, in -toplevel- im.save('e:/11_m.jpg', 'JPEG', quality=90,progressive=1) File "D:\dev\Python24\Lib\site-packages\PIL\Image.py", line 1305, in save save_handler(self, fp, filename) File "D:\dev\Python24\lib\site-packages\PIL\JpegImagePlugin.py", line 409, in _save ImageFile._save(im, fp, [("jpeg", (0,0)+im.size, 0, rawmode)]) File "D:\dev\Python24\Lib\site-packages\PIL\ImageFile.py", line 491, in _save raise IOError("encoder error %d when writing image file" % s) IOError: encoder error -2 when writing image file but When i use : >>> im.save('e:/11_m.jpg', 'JPEG', quality=90) it work. Roger __________________________________________________ ????????????????????????????? http://cn.mail.yahoo.com From fredrik at pythonware.com Fri Oct 27 11:53:41 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 27 Oct 2006 11:53:41 +0200 Subject: [Image-SIG] some trouble about jpeg encode in PIL References: <20061027172424.876A.FEIHU_ROGER@yahoo.com.cn> Message-ID: "feihu_roger" wrote: > I use PIL to thumbnail and save one jpeg. raise one IOException: > > >>> im= Image.open('e:/11.jpg') > >>> im.thumbnail((600,600)) > >>> im.save('e:/11_m.jpg', 'JPEG', quality=90,progressive=1) > > Traceback (most recent call last): > File "", line 1, in -toplevel- > im.save('e:/11_m.jpg', 'JPEG', quality=90,progressive=1) > File "D:\dev\Python24\Lib\site-packages\PIL\Image.py", line 1305, in save > save_handler(self, fp, filename) > File "D:\dev\Python24\lib\site-packages\PIL\JpegImagePlugin.py", line 409, in _save > ImageFile._save(im, fp, [("jpeg", (0,0)+im.size, 0, rawmode)]) > File "D:\dev\Python24\Lib\site-packages\PIL\ImageFile.py", line 491, in _save > raise IOError("encoder error %d when writing image file" % s) > IOError: encoder error -2 when writing image file this is a known limitation; PIL uses the JPEG library's incremental encoding mode, but that doesn't work right in combination with progressive encoding, when the image is too large. to work around this, you can 1. fallback on non-progressive encoding when you get the above error try: im.save(outfile, quality=90, progressive=1) except IOError: im.save(outfile, quality=90) # retry in non-progressive mode and/or 2. tweak the ImageFile.MAXBLOCK value before you save the image; you can either simply set it to something reasonably large (e.g. 256*1024 or even 1024*1024) up front: import ImageFile ImageFile.MAXBLOCK = 1024*1024 or bump the size only if you get the above error. From feihu_roger at yahoo.com.cn Fri Oct 27 12:41:21 2006 From: feihu_roger at yahoo.com.cn (feihu_roger) Date: Fri, 27 Oct 2006 18:41:21 +0800 Subject: [Image-SIG] some trouble about jpeg encode in PIL In-Reply-To: References: <20061027172424.876A.FEIHU_ROGER@yahoo.com.cn> Message-ID: <20061027184042.876E.FEIHU_ROGER@yahoo.com.cn> nice, this is OK. Thanks > this is a known limitation; PIL uses the JPEG library's incremental encoding mode, but > that doesn't work right in combination with progressive encoding, when the image is too > large. to work around this, you can > > 1. fallback on non-progressive encoding when you get the above error > > try: > im.save(outfile, quality=90, progressive=1) > except IOError: > im.save(outfile, quality=90) # retry in non-progressive mode > > and/or > > 2. tweak the ImageFile.MAXBLOCK value before you save the image; you can either > simply set it to something reasonably large (e.g. 256*1024 or even 1024*1024) up front: > > import ImageFile > > ImageFile.MAXBLOCK = 1024*1024 > > or bump the size only if you get the above error. __________________________________________________ ????????????????????????????? http://cn.mail.yahoo.com From short.jones.cipher at gmail.com Sat Oct 28 01:46:59 2006 From: short.jones.cipher at gmail.com (Chris Jone) Date: Fri, 27 Oct 2006 16:46:59 -0700 (PDT) Subject: [Image-SIG] PIL QUAD transform In-Reply-To: References: <003101c6f952$a3fd5180$0301a8c0@orange> Message-ID: <7040656.post@talk.nabble.com> I found the matrix data in Jeff Breidenbach's original posting here on 2005-02-16:- "Data is a 8-tuple (a, b, c, d, e, f, g, h) which contains the coefficients for a perspective transform. For each pixel (x, y) in the output image, the new value is taken from a position (a x + b y + c)/(g x + h y + 1), (d x + e y + f)/(g x + h y + 1) in the input image, rounded to nearest pixel." It works fine in 1.1.5. The question remains: what transform does QUAD apply? I would have expected it to use a perspective transform like the one in the Java Advanced Imaging method getQuadToQuad, which creates a PerspectiveTransform that maps an arbitrary quadrilateral onto another arbitrary quadrilateral. Fredrik Lundh wrote: > > Christopher Jones wrote: > >> I have just discovered that the QUAD transform is not perspective: it >> does >> not preserve straight lines in the original image. Any way of doing a >> perspective transformation? > > in 1.1.5 and later, transform can take a PERSPECTIVE transform matrix, > but I cannot seem to find any documentation on how the matrix data > should look. > > checking the mailing list archives or the source is your best bet. > > > > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > > -- View this message in context: http://www.nabble.com/PIL-QUAD-transform-tf2517519.html#a7040656 Sent from the Python - image-sig mailing list archive at Nabble.com. From feihu_roger at yahoo.com.cn Sat Oct 28 07:58:09 2006 From: feihu_roger at yahoo.com.cn (feihu_roger) Date: Sat, 28 Oct 2006 13:58:09 +0800 Subject: [Image-SIG] resize gif in PIL Message-ID: <20061028135416.5BFE.FEIHU_ROGER@yahoo.com.cn> I use PIL to thumbnail or resizegif. the original gif file :838*462. 38.75KB resize to 600*345, after save as new file. The new file is 86KB. Why is the small gif Larger then original gif file. >>> import Image >>> im = Image.open('e:/1.gif') >>> b=im.resize((600, 345,)) >>> b.show() >>> b.save('e:/13.gif', 'GIF',) __________________________________________________ ????????????????????????????? http://cn.mail.yahoo.com From fredrik at pythonware.com Sat Oct 28 08:31:24 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 28 Oct 2006 08:31:24 +0200 Subject: [Image-SIG] resize gif in PIL In-Reply-To: <20061028135416.5BFE.FEIHU_ROGER@yahoo.com.cn> References: <20061028135416.5BFE.FEIHU_ROGER@yahoo.com.cn> Message-ID: feihu_roger wrote: > I use PIL to thumbnail or resizegif. > the original gif file :838*462. 38.75KB > resize to 600*345, after save as new file. > The new file is 86KB. > Why is the small gif Larger then original gif file. a nearest-neighbour resampling can in fact make the image harder to compress with a non-lossy algorithm, but it's probably mostly because PIL doesn't use a full LZW compressor, originally for legal reasons, but these days mostly because people have better things to do than to write code for a 20-year old crap format designed by a dead company using a patent owned by a bunch of utter nincompoops. are you sure you cannot use JPEG (for photographic images) or PNG (for graphics) instead? From kelvin.chu at uvm.edu Sun Oct 29 17:30:22 2006 From: kelvin.chu at uvm.edu (Kelvin Chu) Date: Sun, 29 Oct 2006 11:30:22 -0500 Subject: [Image-SIG] Altering an Image Sequence Message-ID: <260637DB-1BD5-4374-8E92-10CE5D23CD54@uvm.edu> Hi there; Is it possible to write an image sequence using image-sig? I can use the ImageSequence module to iterate over the frames of a sequence, but I can't seem to figure out how to perform an operation on a specific frame and write that frame back into the sequence. Is it possible to alter a specific frame in an image sequence and then write the sequence to a file? Thanks very much for any help you can offer. Best, Kelvin Chu -- Kelvin Chu, Physics Department, Cook Building 82 University Place, University of Vermont, Burlington, VT 05405-0125 http://www.uvm.edu/~kchu/; (802) 656-0064; Fax: (802) 656-0817 From lists.steve at arachnedesign.net Mon Oct 30 16:00:04 2006 From: lists.steve at arachnedesign.net (Steve Lianoglou) Date: Mon, 30 Oct 2006 10:00:04 -0500 Subject: [Image-SIG] Placing colored pixels next to each other Message-ID: Hi folks, I'm quite new with PIL and I'm trying to do something simple but I'm having a hard time getting this to work the way I want. What I want to do is place two different colored pixels next to each other w/o one trampling over the other. I'm not quite sure what's happening, or what to call it, maybe antialiasing, but lets say I want to place a green pixel at 0,0. Just setting one pixel to red doesn't make a red pixel at all, it's rather grey. If I make a box (say 5x5) it's a bit better, but the color isn't confined to the 3x3 box anymore .. there's a "splatter" of coloring (of lower intensity) in the neighborhood of my red box. That's probably desirable in most cases, but I'm looking for exact color hits ... eventually what I'd like is to have red and green pixels next to each other w/o them interfering with their neighbors. I'm trying to visualize a 6000x200 matrix (in this case a microarray) where each pixel would represent an index of the matrix .. the different colors in each pixel would represent something else. Even if I make the image 18000x600 to do 3x3 pixels for each "index", the red and greens still fight with eachother and I get a nice grey smudge for an image. Is there another approach I should be taking, or a setting I can turn off so this doesn't happen? Oh ... I'm using recently checked out svn version of PIL (thanks for the numpy integration, btw) and am setting the mode of the image to be RGB and RGBA (I'd like transparency to, eventually), for the record. Lastly, I apologize if I'm missing something obvious, looked through the docs located at http://www.pythonware.com/library/pil/handbook/ index.htm but can't seem to make sense of it for what I need to do. Thanks, -steve From fredrik at pythonware.com Mon Oct 30 16:34:00 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 30 Oct 2006 16:34:00 +0100 Subject: [Image-SIG] Placing colored pixels next to each other In-Reply-To: References: Message-ID: Steve Lianoglou wrote: > What I want to do is place two different colored pixels next to each > other w/o one trampling over the other. I'm not quite sure what's > happening, or what to call it, maybe antialiasing, but lets say I > want to place a green pixel at 0,0. > > Just setting one pixel to red doesn't make a red pixel at all, it's > rather grey. If I make a box (say 5x5) it's a bit better, but the > color isn't confined to the 3x3 box anymore .. there's a "splatter" > of coloring (of lower intensity) in the neighborhood of my red box. how are you setting the pixels, and what are you doing to view the result ? > I'm trying to visualize a 6000x200 matrix (in this case a microarray) > where each pixel would represent an index of the matrix .. the > different colors in each pixel would represent something else. 6000x200? are you sure the artifacts you're seeing isn't caused by whatever program you're using to display the image? or do you really have a 6000-pixel wide screen? From lists.steve at arachnedesign.net Mon Oct 30 17:01:21 2006 From: lists.steve at arachnedesign.net (Steve Lianoglou) Date: Mon, 30 Oct 2006 11:01:21 -0500 Subject: [Image-SIG] Placing colored pixels next to each other In-Reply-To: References: Message-ID: <8A5E6CD9-5B76-4A18-B5DD-1839BC122026@arachnedesign.net> Hi Fredrik, >> Just setting one pixel to red doesn't make a red pixel at all, it's >> rather grey. If I make a box (say 5x5) it's a bit better, but the >> color isn't confined to the 3x3 box anymore .. there's a "splatter" >> of coloring (of lower intensity) in the neighborhood of my red box. > > how are you setting the pixels, and what are you doing to view the > result ? I tried a couple of ways -- though I thought the best way for some quick testing would be to use what was suggested in tutorial, something like: ------ image = Image.new("RGBA", (200,6000)) pix = image.load() pix[10,10] = (204,0,0) # red -- or (204,0,0,255) if using RGBA (is that the right way, btw?) image.show() ------ > >> I'm trying to visualize a 6000x200 matrix (in this case a microarray) >> where each pixel would represent an index of the matrix .. the >> different colors in each pixel would represent something else. > > 6000x200? are you sure the artifacts you're seeing isn't caused by > whatever program you're using to display the image? or do you really > have a 6000-pixel wide screen? Ah ... yeah .. I mean, doesn't everybody these days? :-) Sorry, I'm used to indices being referenced by row,col -- so it's actually 200 pixels wide by 6000 tall. I'm using OS X so the show() function is defaulting to use Preview.app. The image is certainly much taller than my monitor but not wider (my resolution is only 1440x900 pixels), so it starts off to be zoomed out, but I zoom enough to make the original pixels large enough to look at. I've actually been playing around with much smaller sized images (30x30) to try some things out before I took a whack at the "real deal" 6000 row microarray, so like in the example above I'd actually have (30,30) instead of (200,6000) Thanks, -steve From fredrik at pythonware.com Mon Oct 30 17:42:53 2006 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 30 Oct 2006 17:42:53 +0100 Subject: [Image-SIG] Placing colored pixels next to each other In-Reply-To: <8A5E6CD9-5B76-4A18-B5DD-1839BC122026@arachnedesign.net> References: <8A5E6CD9-5B76-4A18-B5DD-1839BC122026@arachnedesign.net> Message-ID: Steve Lianoglou wrote: > I'm using OS X so the show() function is defaulting to use Preview.app. and JPEG, I'm afraid: $ more PIL/Image.py ... elif sys.platform == "darwin": format = "JPEG" if not command: command = "open -a /Applications/Preview.app" ... (I wonder how I missed that). what formats do Preview.app support? can you try setting format to None (that writes a PPM file using an optimized code path), or perhaps "PNG". From lists.steve at arachnedesign.net Mon Oct 30 19:16:10 2006 From: lists.steve at arachnedesign.net (Steve Lianoglou) Date: Mon, 30 Oct 2006 13:16:10 -0500 Subject: [Image-SIG] Placing colored pixels next to each other In-Reply-To: References: <8A5E6CD9-5B76-4A18-B5DD-1839BC122026@arachnedesign.net> Message-ID: <9F1D6BB5-EE38-4489-81A2-97EA3903EA9E@arachnedesign.net> > Steve Lianoglou wrote: > >> I'm using OS X so the show() function is defaulting to use >> Preview.app. > > and JPEG, I'm afraid: ... > (I wonder how I missed that). > > what formats do Preview.app support? can you try setting format to > None > (that writes a PPM file using an optimized code path), or perhaps > "PNG". Bingo! Preview.app supports pretty much any format you can throw at it ... except for perhaps PPM(?) I went into the Image.py file and set the format=None. Preview wasn't showing anything here ... it was being called alright, but no image was popping up. I went back in there and changed the format to "PNG" and went through my song and dance and it looks to be working just perfectly. No artifacts around adjacent pixels. Thanks for pointing me in the right direction with that. If there's anything else you'd like me to test w.r.t functionality on the mac, I'd be happy to. Lastly, if I want to use transparency, would creating an RGBA image be the way to go? I'm setting the color with a 4-tuple, of which I think the last number is the transparency (0-255?), but it seemingly has no effect on the opacity of the area I'm coloring (or the pixel). I'm trying to create a "heat map" over my matrix, where full opacity would be something like "the strongest signal", and then I'd decrease opacity/increase transparency in the blocks/pixels where the signal is weaker. Perhaps merging two images is how I should be doing it? I found this post that seems to take this approach: http://mail.python.org/pipermail/python-list/1999-May/003369.html Is that the best way to do it? Thanks again, -steve