From brad at allendev.com Thu Apr 5 20:25:03 2007 From: brad at allendev.com (Brad Allen) Date: Thu, 5 Apr 2007 13:25:03 -0500 Subject: [Image-SIG] PIL supporting TIFF compressed using group 4? Message-ID: Hello, I am new to this list, having gotten involved in a project at work that uses PIL. There is one place where we are using wxImage to read a TIFF which the PIL 1.1.6 apparently cannot because the image has group 4 compression. There are some scant mentions earlier on this list and in comp.lang.python about a patch for PIL support for TIFF group 4, but I can seem to find any confirmation that it exists or how to get it. Any insight would be appreciated...thanks! From brad at allendev.com Thu Apr 5 20:46:52 2007 From: brad at allendev.com (Brad Allen) Date: Thu, 5 Apr 2007 13:46:52 -0500 Subject: [Image-SIG] seeking guidance on image conversion Message-ID: Hello, I am new to this list, having gotten involved in a project at work that uses PIL. I am looking for guidance in a few areas, hoping to find a better way than our methods for manipulating images. We have a workflow which involves converting various file formats to TIFF, and allowing them to be viewed and manipulated in a wxPython app. Currently we are calling on some external binaries to perform these conversions on a Linux server, and in some cases the Windows desktop clients have to do some conversions as well. It would be nice if there were some more Python native approaches available. The goal is to get everything into a compressed TIFF format. Currently we do that for Word documents and PDF documents. We also need to convert between multipage TIFF and single page TIFF. Here is a list of the image conversions we are performing: * One of the Python scripts is calling Linux tiffsplit command to convert multipage faxes (TIFF group 4 compressed) into collections of single page TIFFs. * The wxPython app is calling GnuWin32's tiffcp.exe to rejoin single page TIFFs into multipage TIFFs. * We're calling the ImageMagick convert command to make PDFs into TIFFs. * We're calling an Open Office 1.1.5 command line tool to convert Word documents to PDF (which then get converted to TIFF by ImageMagick). In some of these cases there may be C libraries we could wrap, but if someone has already done that work or if there is a better approach I would be grateful to hear about it. Thanks! From waldemar.osuch at gmail.com Fri Apr 6 00:40:49 2007 From: waldemar.osuch at gmail.com (Waldemar Osuch) Date: Thu, 5 Apr 2007 16:40:49 -0600 Subject: [Image-SIG] seeking guidance on image conversion In-Reply-To: References: Message-ID: <6fae95540704051540s2d3c0313q89209214c64781a@mail.gmail.com> > * One of the Python scripts is calling Linux tiffsplit command to > convert multipage faxes (TIFF group 4 compressed) into collections of > single page TIFFs. pytiff library should be able to do it (http://www.haynold.com/software_projects/2004/pytiff/) I have used it on small scale for the same purpose. > > * The wxPython app is calling GnuWin32's tiffcp.exe to rejoin single > page TIFFs into multipage TIFFs. pytiff again. > * We're calling the ImageMagick convert command to make PDFs into TIFFs. Alternatively one could use Ghostscript for the purpose. They provide even a shared library that could be driven using ctypes. > * We're calling an Open Office 1.1.5 command line tool to convert > Word documents to PDF (which then get converted to TIFF by > ImageMagick). If windows machine has PDFCreator installed (http://www.pdfforge.org/products/pdfcreator) one could use Python COM to drive Word and print directly into PDF format. Waldemar From brad at allendev.com Fri Apr 6 19:59:00 2007 From: brad at allendev.com (Brad Allen) Date: Fri, 6 Apr 2007 12:59:00 -0500 Subject: [Image-SIG] seeking guidance on image conversion In-Reply-To: <6fae95540704051540s2d3c0313q89209214c64781a@mail.gmail.com> References: <6fae95540704051540s2d3c0313q89209214c64781a@mail.gmail.com> Message-ID: At 4:40 PM -0600 4/5/07, Waldemar Osuch wrote: >>* One of the Python scripts is calling Linux tiffsplit command to >>convert multipage faxes (TIFF group 4 compressed) into collections of >>single page TIFFs. > >pytiff library should be able to do it >(http://www.haynold.com/software_projects/2004/pytiff/) >I have used it on small scale for the same purpose. Thanks, Waldemar. pytiff sounds interesting though I am worried it doesn't appear to be under active development. However, if it works then maybe it doesn't need to be active. > >>* We're calling the ImageMagick convert command to make PDFs into TIFFs. > >Alternatively one could use Ghostscript for the purpose. They provide >even a shared library that could be driven using ctypes. That sounds like an interesting possible future avenue; I've heard ctypes is great to work with though I don't know much about it or Ghostscript. I guess we will stick with calling the convert command for now but I will keep this idea in mind. From kzn.kpolice at gmail.com Tue Apr 10 08:34:11 2007 From: kzn.kpolice at gmail.com (=?ISO-8859-1?Q?C=E9sar_P=E9rez?=) Date: Tue, 10 Apr 2007 01:34:11 -0500 Subject: [Image-SIG] Help with PIL, Imagemagick Composite function in PIL? Message-ID: <1176186852.9351.17.camel@localhost.localdomain> Hi, I am new to this list but and i have a small problem with PIL. I am looking for a function that works like composite does in imagemagick. If you don't know, composite puts the first image above the second one and it's like pasting. I have tried PIL paste but I can't get it to work as I want, specially if my images have alpha channels. For example I have an example script: ------------------------ from PIL import Image dtop = Image.open("dtop.png") frame = Image.open("frame.png") dtop.paste(frame,(0,0),frame) dtop.save("test.png") ------------------------ I tried every form of paste but I always get this result or worst. Using the images from [1] the output image is different, I uploaded the output file created by IM and PIL to [1] and as you can see it's not the same. Imagemagick output is im.png and PIL is pil.png. You can clearly see the difference if you put the images against a background color other than white or by opening in something like GIMP or any viewer that shows a checker pattern to represent the transparency. Imagemagick does it as I want but PIL doesn't. I hope somebody can help or knows how to do it because I prefer using only PIL as it's the only thing that I don't know how to do without Imagemagick. 1. http://www.capc-online.net/images/temp/ THX C?sar P?rez From snaury at gmail.com Tue Apr 10 11:07:21 2007 From: snaury at gmail.com (Alexey Borzenkov) Date: Tue, 10 Apr 2007 13:07:21 +0400 Subject: [Image-SIG] Help with PIL, Imagemagick Composite function in PIL? In-Reply-To: <1176186852.9351.17.camel@localhost.localdomain> References: <1176186852.9351.17.camel@localhost.localdomain> Message-ID: On 4/10/07, C?sar P?rez wrote: > Hi, > I am new to this list but and i have a small problem with PIL. > > I am looking for a function that works like composite does in > imagemagick. [..snip..] > from PIL import Image > > dtop = Image.open("dtop.png") > frame = Image.open("frame.png") > > dtop.paste(frame,(0,0),frame) > dtop.save("test.png") > ------------------------ > I tried every form of paste but I always get this result or worst. The problem you have happens because alpha channel of images *also* gets composited using the mask you specified. To do it right you actually need to split image, save target image alpha channel and after compositing merge it back using original alpha channel: from PIL import Image dtop = Image.open("dtop.png") frame = Image.open("frame.png") assert dtop.mode == "RGBA" r,g,b,a = dtop.split() dtop = Image.merge("RGB", (r,g,b)) dtop.paste(frame,(0,0),frame) r,g,b = dtop.split() dtop = Image.merge("RGBA", (r,g,b,a)) dtop.save("test.png") Best regards, Alexey. From michele.petrazzo at unipex.it Tue Apr 10 11:43:37 2007 From: michele.petrazzo at unipex.it (Michele Petrazzo - Unipex srl) Date: Tue, 10 Apr 2007 11:43:37 +0200 Subject: [Image-SIG] seeking guidance on image conversion In-Reply-To: References: Message-ID: <461B5C49.8080307@unipex.it> Brad Allen wrote: > Hello, > Hello, > I am new to this list, having gotten involved in a project at work > that uses PIL. I am looking for guidance in a few areas, hoping to > find a better way than our methods for manipulating images. > > We have a workflow which involves converting various file formats to > TIFF, and allowing them to be viewed and manipulated in a wxPython > app. > A solution can be that already replied. Another can be to use freeimagepy that is born because PIL doesn't handle, like I need, the g3, g4 and multipage tiff files. I create it, and I use it, for hylapex, a fax client that need to work with fax files, that are in g3 and g4 format! My old solution, like you wrote, was use the tiff gnuwin32 files, but work with a dll a some python (ctypes) code, are better! :) > Here is a list of the image conversions we are performing: > > * One of the Python scripts is calling Linux tiffsplit command to > convert multipage faxes (TIFF group 4 compressed) into collections of > single page TIFFs. Ok with freeimagepy (convertToMultiPage and convertToSinglePages) > > * The wxPython app is calling GnuWin32's tiffcp.exe to rejoin single > page TIFFs into multipage TIFFs. > Like above > * We're calling the ImageMagick convert command to make PDFs into > TIFFs. > I use ghostscript (present on linux, but not on win, where I need it and install it every time) for do all the work. It's not so difficult to do the work. If you need some questions, I'm here. > * We're calling an Open Office 1.1.5 command line tool to convert > Word documents to PDF (which then get converted to TIFF by > ImageMagick). > Like said, you can use pdfcreator or ghostscript itself, that has the psXXX and pdfXXX devices. > In some of these cases there may be C libraries we could wrap, but if > someone has already done that work or if there is a better approach > I would be grateful to hear about it. > My image library wrapper are there! If you want to contribute for add the part that I don't already wrap, contact me! > Thanks! > Bye, Michele -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 3273 bytes Desc: S/MIME Cryptographic Signature Url : http://mail.python.org/pipermail/image-sig/attachments/20070410/06b119ce/attachment.bin From douglas at paradise.net.nz Wed Apr 11 01:48:53 2007 From: douglas at paradise.net.nz (Douglas Bagnall) Date: Wed, 11 Apr 2007 11:48:53 +1200 Subject: [Image-SIG] Help with PIL, Imagemagick Composite function in PIL? In-Reply-To: References: <1176186852.9351.17.camel@localhost.localdomain> Message-ID: <461C2265.9000607@paradise.net.nz> Alexey Borzenkov wrote: > The problem you have happens because alpha channel of images *also* > gets composited using the mask you specified. To do it right you > actually need to split image, save target image alpha channel and > after compositing merge it back using original alpha channel: Alexey, I think you are completely right about the problem, but the solution can be quite a bit simpler: dtop = Image.open("dtop.png") frame = Image.open("frame.png") dtop.paste(frame.convert('RGB'), (0,0), frame) dtop.save("test.png") I would say that this alpha-merging quirk comes close to being a bug -- it's probably not what most people expect. douglas From kzn.kpolice at gmail.com Wed Apr 11 06:00:58 2007 From: kzn.kpolice at gmail.com (=?ISO-8859-1?Q?C=E9sar_P=E9rez?=) Date: Tue, 10 Apr 2007 23:00:58 -0500 Subject: [Image-SIG] Help with PIL, Imagemagick Composite function in PIL? In-Reply-To: <461C2265.9000607@paradise.net.nz> References: <1176186852.9351.17.camel@localhost.localdomain> <461C2265.9000607@paradise.net.nz> Message-ID: <1176264058.5981.1.camel@localhost.localdomain> Thanks to both of you and yes I was expecting the paste function to work just like a paste in any Image Editor. C?sar On Wed, 2007-04-11 at 11:48 +1200, Douglas Bagnall wrote: > Alexey Borzenkov wrote: > > > The problem you have happens because alpha channel of images *also* > > gets composited using the mask you specified. To do it right you > > actually need to split image, save target image alpha channel and > > after compositing merge it back using original alpha channel: > > Alexey, I think you are completely right about the problem, but the > solution can be quite a bit simpler: > > dtop = Image.open("dtop.png") > frame = Image.open("frame.png") > > dtop.paste(frame.convert('RGB'), (0,0), frame) > dtop.save("test.png") > > > I would say that this alpha-merging quirk comes close to being a bug -- > it's probably not what most people expect. > > douglas > From snaury at gmail.com Wed Apr 11 07:26:45 2007 From: snaury at gmail.com (Alexey Borzenkov) Date: Wed, 11 Apr 2007 09:26:45 +0400 Subject: [Image-SIG] Help with PIL, Imagemagick Composite function in PIL? In-Reply-To: <461C2265.9000607@paradise.net.nz> References: <1176186852.9351.17.camel@localhost.localdomain> <461C2265.9000607@paradise.net.nz> Message-ID: On 4/11/07, Douglas Bagnall wrote: > Alexey, I think you are completely right about the problem, but the > solution can be quite a bit simpler: > > dtop = Image.open("dtop.png") > frame = Image.open("frame.png") > > dtop.paste(frame.convert('RGB'), (0,0), frame) > dtop.save("test.png") Hmm... The good part I see in this solution is that when image is converted from RGBA to RGB it just so happens that its pixelsize is still 4 but 4th byte is filled with 255. Then paste_mask_RGBA kicks in, and if dtop has alpha channel it will composite its alpha channel with 255, decreasing dtop transparency where frame is not completely transparent. To be honest I'm not sure what is generally expected in this situation, though looking at the way antigrain does rgba blending I see that it essentially has this formula: a = a * (1 - alpha) + 1 * alpha Which is just the way it works in the code above (and absolutely not the way it'd worked in my code). So if this behavior is expected my example wouldn't even work as it should, thanks for showing that. :) Best regards, Alexey. From patric.engelkins at verizonbusiness.com Mon Apr 9 17:40:18 2007 From: patric.engelkins at verizonbusiness.com (Engelkins, Patric P) Date: Mon, 09 Apr 2007 15:40:18 +0000 Subject: [Image-SIG] Plone - The _imaging C module is not installed (Solaris 9) Message-ID: <3E71B90C10702F4B8AB037486190518401F17D38@ASHEVS004.mcilink.com> Hello all, I've been working on this one issue for about two weeks and I'm at my wits end. :-( I'm trying to get the user picture upload feature of Plone/Preferences to work but I keep getting the error: The _imaging C module is not installed Now I've had the help of a programmer and a Solaris admin and we've Google and tried several things but none have worked. Yes, I have successfully installed PIL-1.1.5 and 1.1.6 as the Plone install from source explains. And how the PIL README states. http://plone.org/documentation/how-to/setup-from-source There is not much information on guides out there specifically targeting the Solaris environment so this has definitely been a trial and error. I've gotten everything but this _imaging C module thing working as it should be. Here is my current environment and error details: SUN E4000 - SunOS 5.9 Generic_118558-24 sun4u sparc SUNW,Ultra-Enterprise I have installed all the dependencies as suggested for the 2.5.2 Plone version and Solaris 9 supporting dependencies. Plone-2.5.2-1.tar Zope-2.9.6-final.tar DocFinderTab-1.0.2.tar Imaging-1.1.5.tar Imaging-1.1.6.tar.gz freetype-2.3.1-sol9-sparc-local gcc-3.4.6-sol9-sparc-local.gz jpeg-6b-sol9-sparc-local jpeg2ps-1.9-sol9-sparc-local libiconv-1.9.2-sol9-sparc-local.gz make-3.81-sol9-sparc-local.gz python-2.4.3-sol9-sparc-local.gz readline-5.2-sol9-sparc-local.gz zlib-1.2.3-sol9-sparc-local Here is all the error report that I copied and pasted: ************************************************************************ ********** Error Type ImportError Error Value The _imaging C module is not installed Version Info: Plone version: 2.5.2 Zope version: (Zope 2.9.6-final, python 2.4.3, sunos5) Apache version: CMF version (if known): CMF-1.6.2 Browser(s) and version(s): Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3 Operating system: sunos5 Python version: 2.4.3 (#1, Jul 31 2006, 06:30:48) [GCC 3.3.2] Debug mode: No Installed Products: Marshall 0.6.6-final MimetypesRegistry 1.4.1-final installed OFSP OFSP-1-0-0 PageTemplates PageTemplates-1-4-0 PasswordResetTool 0.4.2 installed PlacelessTranslationService 1.3.4 PloneErrorReporting 1.0 installed PloneLanguageTool 1.5 PlonePAS 2.2 installed PloneTestCase 0.9.0 PloneTranslations 2.6.1 PluggableAuthService PluggableAuthService-1.4.1 PluginIndexes PluginRegistry 1.1.1 PortalTransforms 1.5.0-final installed PyboomSkin 1.2 installed PythonScripts PythonScripts-2-0-0 ResourceRegistries 1.3.4 installed SecureMailHost 1.0.4 Sessions SiteAccess SiteAccess-2-0-0 SiteErrorLog StandardCacheManagers StandardCacheManagers-1-1-0 TAKAKoboltTheme 1.0.1 TemporaryFolder Transience ZCTextIndex ZCatalog ZCatalog-2-2-0 ZGadflyDA ZODBMountPoint ZReST 1.1 ZSQLMethods ZWiki ZWiki-0-58-0 ZopeTutorial Zope Tutorial 1.2 kupu kupu 1.3.9 installed statusmessages 2.0.1 validation 1.5.0-final Traceback: Traceback (innermost last): Module ZPublisher.Publish, line 115, in publish Module ZPublisher.mapply, line 88, in mapply Module ZPublisher.Publish, line 41, in call_object Module Products.CMFFormController.FSControllerPageTemplate, line 90, in __call__ Module Products.CMFFormController.BaseControllerPageTemplate, line 28, in _call Module Products.CMFFormController.ControllerBase, line 232, in getNext - __traceback_info__: ['id = personalize_form', 'status = success', 'button=Save', 'errors={}', 'context=', 'kwargs={}', 'next_action=None', ''] Module Products.CMFFormController.Actions.TraverseTo, line 38, in __call__ Module ZPublisher.mapply, line 88, in mapply Module ZPublisher.Publish, line 41, in call_object Module Products.CMFFormController.FSControllerPythonScript, line 104, in __call__ Module Products.CMFFormController.Script, line 145, in __call__ Module Products.CMFCore.FSPythonScript, line 108, in __call__ Module Shared.DC.Scripts.Bindings, line 311, in __call__ Module Shared.DC.Scripts.Bindings, line 348, in _bindAndExec Module Products.CMFCore.FSPythonScript, line 164, in _exec Module None, line 31, in personalize - - Line 31 Module Products.PlonePAS.tools.membership, line 445, in changeMemberPortrait Module Products.CMFPlone.MembershipTool, line 181, in changeMemberPortrait Module Products.CMFPlone.utils, line 754, in scale_image Module PIL.Image, line 1372, in save Module PIL.ImageFile, line 155, in load Module PIL.ImageFile, line 223, in load_prepare Module PIL.Image, line 36, in __getattr__ ImportError: The _imaging C module is not installed ************************************************************************ **** Yet when installing the PIL product it installs without error?! Other details: I've created a zadmin user with a zope group The whole site is in its own directory: /u01/app/zope: zadmin at u2:> ls total 18 drwxr-xr-x 9 zadmin zope 512 Apr 3 11:07 Zope-2.9.6-final/ drwxr-xr-x 2 zadmin zope 1024 Apr 3 11:38 bin/ drwxr-xr-x 2 zadmin zope 512 Apr 3 11:36 doc/ drwxr-xr-x 10 zadmin zope 512 Apr 3 14:08 instance1/ drwxr-xr-x 3 zadmin zope 512 Apr 3 11:34 lib/ drwxr-xr-x 10 zadmin zope 512 Apr 3 11:36 skel/ drwxr-xr-x 5 zadmin zope 1024 Apr 3 15:14 source/ I've been consistent with using python2.4 when running any python scripts. I direct zope build to use python 2.4 as well. I've updated the the zadmin $PATH (via .profile permanently) zadmin at u2:> echo $PATH /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/insight/r/bin:/usr/loc al/bin:/usr/sbin:/usr/ccs/bin: /usr/openwin/bin:/usr/apache/bin:/u01/app/zope/instance1/bin:/usr/local/ lib:/usr/local/lib/python2.4 and zadmin at u2:> echo $LD_LIBRARY_PATH /usr/local/lib:/opt/CA/SharedComponents/lib Debug Information * Zope version: (Zope 2.9.6-final, python 2.4.3, sunos5) * Python version: 2.4.3 (#1, Jul 31 2006, 06:30:48) [GCC 3.3.2] * System Platform: sunos5 * SOFTWARE_HOME: /u01/app/zope/lib/python * INSTANCE_HOME: /u01/app/zope/instance1 * CLIENT_HOME: /u01/app/zope/instance1/var * Process ID: 18363 (4) * Running for: 22 min 5 sec * sys.path: /u01/app/zope/instance1/lib/python /u01/app/zope/instance1/lib/python /u01/app/zope/lib/python/Zope2/Startup /u01/app/zope/instance1/Products/ATContentTypes/thirdparty /u01/app/zope/lib/python /u01/app/zope/instance1 /usr/local/lib/python24.zip /usr/local/lib/python2.4 /usr/local/lib/python2.4/plat-sunos5 /usr/local/lib/python2.4/lib-tk /usr/local/lib/python2.4/lib-dynload /usr/local/lib/python2.4/site-packages /usr/local/lib/python2.4/site-packages/PIL Please, if you need any other information let me know. This is the last issue and then the site is 100% functional and I can start configuring it to be our new team website. Thank you, Patric -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20070409/428c0f9e/attachment.htm From crouad01 at luther.edu Fri Apr 13 23:06:26 2007 From: crouad01 at luther.edu (crouad01 at luther.edu) Date: Fri, 13 Apr 2007 16:06:26 -0500 (CDT) Subject: [Image-SIG] PIL on a Mac Message-ID: <60764.172.21.42.248.1176498386.squirrel@webmail.luther.edu> Hello Support, I'm sitting here looking at the ReadMe for the PIL, and I realized something a few moments back: this is more complicated than I thought it would be. If it isn't too difficult, would you be able to tell me how I could put the PIL in my computer so I can just play around with Python and images. I am currently in a introductory course to computer science and we are using Python. I am running it on a MacBook Pro right now. I guess I had to download a MacPython in order to make Python work on my system. I'm not too sure, but it does seem to work. The problem that I'm having now seems to be stemming from his "Imaging-1.1.6" folder that I just downloaded. What should I do with it? I was looking at the ReadMe (that's where I got this e-mail) and it says that I'll need to download more things (correct?). My professor did say something about Fink. Now, I don't want you guys to go totally out of your way because there is a computer lab on campus that I could do all this on, but I would like it to be on my computer, too, just so I can finish the homework up and play around with image transformations. Thank you. Adam Crouse From jwt at onjapan.net Sat Apr 14 00:58:41 2007 From: jwt at onjapan.net (Jim Tittsler) Date: Sat, 14 Apr 2007 10:58:41 +1200 Subject: [Image-SIG] PIL on a Mac In-Reply-To: <60764.172.21.42.248.1176498386.squirrel@webmail.luther.edu> References: <60764.172.21.42.248.1176498386.squirrel@webmail.luther.edu> Message-ID: <55A5893C-F36C-45C5-87C8-E276C31F5378@onjapan.net> On Apr 14, 2007, at 09:06, crouad01 at luther.edu wrote: > would be. If it isn't too difficult, would you be able to tell me > how I > could put the PIL in my computer so I can just play around with > Python and > images. The easiest way is to download one of the pre-built PIL packages from: http://pythonmac.org/packages/ If you are using the currently recommended Python 2.5 installation, you want: http://pythonmac.org/packages/py25-fat/dmg/PIL-1.1.5-py2.5- macosx10.4.dmg -- Jim Tittsler http://www.OnJapan.net/ GPG: 0x01159DB6 Python Starship http://Starship.Python.net/crew/jwt/ Mailman IRC irc://irc.freenode.net/#mailman From ole.trenner at gmx.de Sat Apr 14 18:32:22 2007 From: ole.trenner at gmx.de (Ole Trenner) Date: Sat, 14 Apr 2007 18:32:22 +0200 Subject: [Image-SIG] PIL ImageGrab clipboard block Message-ID: <46210216.4010100@gmx.de> Hi List, I'm currently using the ImageGrab module of PIL for a small image upload client. I've noticed that the ImageGrab.grabclipboard() method seems to somehow block the clipboard. I'll try to explain: This is what works: When the Windows clipboard contains image data when first trying to use ImageGrab.grabclipboard() it works as supposed. You can further change the clipboard contents (copy image data from another application) and reinvoke ImageGrab.grabclipboard() to fetch the new data. And this is what doesn't work: When the windows clipboard contains text (or nothing) when trying to use ImageGrab.grabclipboard(), any subsequent calls to ImageGrab.grabclipboard() fail. AND it seems as if the clipboard was blocked, i.e. none of my graphical apps is able to copy image data to the clipboard until my upload client is finished. This minimal loop can be used to test the behavior: import Image, ImageGrab while True: img = ImageGrab.grabclipboard() if isinstance(img, Image.Image): print "Found Image" else: print "No Image" print "Press Enter to continue...", raw_input() I'd love to see a way to "reset" the clipboard or fix my app to be able to paste image data even if the clipboard was empty or just contained text on startup. Thanks in advance, Ole Trenner From snaury at gmail.com Sat Apr 14 18:56:42 2007 From: snaury at gmail.com (Alexey Borzenkov) Date: Sat, 14 Apr 2007 20:56:42 +0400 Subject: [Image-SIG] PIL ImageGrab clipboard block In-Reply-To: <46210216.4010100@gmx.de> References: <46210216.4010100@gmx.de> Message-ID: On 4/14/07, Ole Trenner wrote: > Hi List, > > I'm currently using the ImageGrab module of PIL for a small image upload > client. I've noticed that the ImageGrab.grabclipboard() method seems to > somehow block the clipboard. This is a bug, you can use this patch to fix that: diff -ruN Imaging-1.1.6-orig/display.c Imaging-1.1.6/display.c --- Imaging-1.1.6-orig/display.c Sun Dec 3 14:51:25 2006 +++ Imaging-1.1.6/display.c Sat Apr 14 20:54:37 2007 @@ -496,6 +496,7 @@ if (!handle) { /* FIXME: add CF_HDROP support to allow cut-and-paste from the explorer */ + CloseClipboard(); Py_INCREF(Py_None); return Py_None; } Best regards, Alexey. From feihu_roger at yahoo.com.cn Tue Apr 17 08:11:26 2007 From: feihu_roger at yahoo.com.cn (feihu_roger) Date: Tue, 17 Apr 2007 14:11:26 +0800 Subject: [Image-SIG] problem about color about some jpeg Message-ID: <20070417140942.6BC8.FEIHU_ROGER@yahoo.com.cn> I had a file f.jpg. It can be corrent show by acdsee or IrfanView, but can not open it by IE. >>> f=Image.open('f.jpg') >>> f.show() The new pic is color error, please see screen_snape.jpg . f.jpg can be get from : http://farm1.static.flickr.com/174/462386397_579d1f4915_o.jpg (IE only see red cross) screen_snape.jpg gan be get from:http://farm1.static.flickr.com/216/462386405_d24140a4b9_o.jpg My mother language is't English. From ced at bernispa.com Tue Apr 17 09:05:51 2007 From: ced at bernispa.com (Cesare Leonardi) Date: Tue, 17 Apr 2007 09:05:51 +0200 Subject: [Image-SIG] problem about color about some jpeg In-Reply-To: <20070417140942.6BC8.FEIHU_ROGER@yahoo.com.cn> References: <20070417140942.6BC8.FEIHU_ROGER@yahoo.com.cn> Message-ID: <462471CF.6050408@bernispa.com> feihu_roger ha scritto: > I had a file f.jpg. It can be corrent show by acdsee or IrfanView, but > can not open it by IE. > >>>> f=Image.open('f.jpg') >>>> f.show() > > The new pic is color error, please see screen_snape.jpg . > > f.jpg can be get from : http://farm1.static.flickr.com/174/462386397_579d1f4915_o.jpg > (IE only see red cross) > > screen_snape.jpg gan be get from:http://farm1.static.flickr.com/216/462386405_d24140a4b9_o.jpg Your images are JPEG using CMYK colorspace (normally JPEG use RGB colorspace). It is a format that many image viewer cannot handle (in fact IE and Firefox cannot shows them) but still used in some graphics context. It's known that PIL has some problems treating JPEG CMYK, as reported at least in these thread started from me: http://mail.python.org/pipermail/image-sig/2006-April/003862.html http://mail.python.org/pipermail/image-sig/2007-February/004336.html Sorry but in the meantime the web space i've used in these thread to post some sample images and some text note, is not available to me anymore, so the links are broken. However, in the first thread Kevin Cazabon has posted a patch that resolved the problem with all my images and that was accepted by PIL developers. The problem is that the patch applied is not the same as proposed by Kevin and the upstream version still shows problems on some images. If you want to try, some month ago i've verified that Kevin's patch still applies correctly to 1.1.6. You can rename your "JpegImagePlugin.py" to something else and substituting it with attached one (remove "KevinPatch"). Good luck. ;-) Cesare. -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: JpegImagePlugin.KevinPatch.py Url: http://mail.python.org/pipermail/image-sig/attachments/20070417/7fd17231/attachment.asc From feihu_roger at yahoo.com.cn Tue Apr 17 13:08:29 2007 From: feihu_roger at yahoo.com.cn (feihu_roger) Date: Tue, 17 Apr 2007 19:08:29 +0800 Subject: [Image-SIG] problem about color about some jpeg In-Reply-To: <462471CF.6050408@bernispa.com> References: <20070417140942.6BC8.FEIHU_ROGER@yahoo.com.cn> <462471CF.6050408@bernispa.com> Message-ID: <20070417190305.69E9.FEIHU_ROGER@yahoo.com.cn> Thank u very much. The patch work current. > You can rename your "JpegImagePlugin.py" to something else and > substituting it with attached one (remove "KevinPatch"). > > Good luck. ;-) From snaury at gmail.com Wed Apr 18 07:02:23 2007 From: snaury at gmail.com (Alexey Borzenkov) Date: Wed, 18 Apr 2007 09:02:23 +0400 Subject: [Image-SIG] problem about color about some jpeg In-Reply-To: <462471CF.6050408@bernispa.com> References: <20070417140942.6BC8.FEIHU_ROGER@yahoo.com.cn> <462471CF.6050408@bernispa.com> Message-ID: Just in case, attaching Kevin's patch as unified diff: Index: JpegImagePlugin.py =================================================================== --- JpegImagePlugin.py (revision 207) +++ JpegImagePlugin.py (revision 208) @@ -32,7 +32,7 @@ __version__ = "0.5" import array, string -import Image, ImageFile +import Image, ImageFile, ImageChops def i16(c,o=0): return ord(c[o+1]) + (ord(c[o])<<8) @@ -270,8 +270,11 @@ handler(self, i) if i == 0xFFDA: # start of scan rawmode = self.mode - if self.mode == "CMYK": - rawmode = "CMYK;I" + # patch by Kevin Cazabon to comment this out - nobody should be using Photoshop 2.5 any more (and it breaks newer versions) + # CMYK images are still inverted, we'll fix that just before returning. + #if self.mode == "CMYK" and self.info.has_key("adobe"): + # rawmode = "CMYK;I" # Photoshop 2.5 is broken! + self.tile = [("jpeg", (0,0) + self.size, 0, (rawmode, ""))] # self.__offset = self.fp.tell() break @@ -282,6 +285,10 @@ else: raise SyntaxError("no marker found") + # patch by Kevin Cazabon to re-invert CMYK JPEG files + if self.mode == "CMYK": + self.im = ImageChops.invert(self).im + def draft(self, mode, size): if len(self.tile) != 1: @@ -378,7 +385,7 @@ "RGB": "RGB", "RGBA": "RGB", "RGBX": "RGB", - "CMYK": "CMYK;I", + "CMYK": "CMYK", "YCbCr": "YCbCr", } @@ -406,6 +413,10 @@ dpi[0], dpi[1] ) + if im.mode == "CMYK": + # invert it so it's handled correctly in Photoshop/etc. - Kevin Cazabon. + im = ImageChops.invert(im) + ImageFile._save(im, fp, [("jpeg", (0,0)+im.size, 0, rawmode)]) def _save_cjpeg(im, fp, filename): Best regards, Alexey. -------------- next part -------------- A non-text attachment was scrubbed... Name: JpegImagePlugin-kevin-cmyk.patch Type: application/octet-stream Size: 1927 bytes Desc: not available Url : http://mail.python.org/pipermail/image-sig/attachments/20070418/e567bd08/attachment.obj From paulrigor at gmail.com Fri Apr 13 23:41:52 2007 From: paulrigor at gmail.com (Paul Rigor) Date: Fri, 13 Apr 2007 14:41:52 -0700 Subject: [Image-SIG] PIL on a Mac In-Reply-To: <60764.172.21.42.248.1176498386.squirrel@webmail.luther.edu> References: <60764.172.21.42.248.1176498386.squirrel@webmail.luther.edu> Message-ID: <78771fdc0704131441q4c949abbsd145831e551e9de2@mail.gmail.com> Hi, You should checkout http://www.finkproject.org/ which creates a 'sandbox' for gnu/unix/non-mac utilities. It comes with a GUI which lets you select packages from their repository (similar to a yum/apt-get repository for several linux distributions out there). It also comes with command-line tools, if you prefer. Once you've installed fink and python, you can directly call the python binary installed in the fink default bin (eg, /sw/bin/) when using the setup tools (eg, setup.py) which comes with PIL. Using this fink 'python' will install the PIL package inside python's corresponding site-packages folder. In order to set the fink environment automatically every time you use the terminal, you'll need to modify your .bash_profile. Add the following line "test -r /sw/bin/init.sh && . /sw/bin/init.sh". You'll of course need to adapt the fink installation path as you see fit. Good luck, Paul On 4/13/07, crouad01 at luther.edu wrote: > > Hello Support, > I'm sitting here looking at the ReadMe for the PIL, and I realized > something a few moments back: this is more complicated than I thought it > would be. If it isn't too difficult, would you be able to tell me how I > could put the PIL in my computer so I can just play around with Python and > images. I am currently in a introductory course to computer science and we > are using Python. I am running it on a MacBook Pro right now. I guess I > had to download a MacPython in order to make Python work on my system. I'm > not too sure, but it does seem to work. The problem that I'm having now > seems to be stemming from his "Imaging-1.1.6" folder that I just > downloaded. What should I do with it? I was looking at the ReadMe (that's > where I got this e-mail) and it says that I'll need to download more > things (correct?). My professor did say something about Fink. > Now, I don't want you guys to go totally out of your way because there is > a computer lab on campus that I could do all this on, but I would like it > to be on my computer, too, just so I can finish the homework up and play > around with image transformations. > Thank you. > Adam Crouse > > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > -- http://www.nrdcaction.org/gwtakeaction http://www.nrdcactionfund.org/tellafriend.asp http://www.savetheinternet.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20070413/8df6369a/attachment.htm From feihu_roger at yahoo.com.cn Tue Apr 17 05:29:47 2007 From: feihu_roger at yahoo.com.cn (feihu_roger) Date: Tue, 17 Apr 2007 11:29:47 +0800 Subject: [Image-SIG] some jpeg is error. Message-ID: <20070417110150.6BC5.FEIHU_ROGER@yahoo.com.cn> I had a file f.jpg. It can be corrent show by acdsee or IrfanView, but can not open it by IE. >>> f=Image.open('f.jpg') >>> f.show() The new pic is color error, please see screen_snape.jpg . f.jpg can be get from : http://farm1.static.flickr.com/174/462386397_579d1f4915_o.jpg (IE only see red cross) screen_snape.jpg gan be get from:http://farm1.static.flickr.com/216/462386405_d24140a4b9_o.jpg My mother language is't English. From janssen at parc.com Tue Apr 24 17:36:37 2007 From: janssen at parc.com (Bill Janssen) Date: Tue, 24 Apr 2007 08:36:37 PDT Subject: [Image-SIG] PIL on a Mac In-Reply-To: <60764.172.21.42.248.1176498386.squirrel@webmail.luther.edu> References: <60764.172.21.42.248.1176498386.squirrel@webmail.luther.edu> Message-ID: <07Apr24.083646pdt."57996"@synergy1.parc.xerox.com> > If it isn't too difficult, would you be able to tell me how I > could put the PIL in my computer so I can just play around with Python and > images. I am currently in a introductory course to computer science and we > are using Python. I am running it on a MacBook Pro right now. You could do it the way that I do it. > I guess I > had to download a MacPython in order to make Python work on my system. First of all, Python comes pre-installed on your Mac. No need to download more MacPython. All you have to do is install PIL. > I'm > not too sure, but it does seem to work. The problem that I'm having now > seems to be stemming from his "Imaging-1.1.6" folder that I just > downloaded. What should I do with it? I was looking at the ReadMe (that's > where I got this e-mail) and it says that I'll need to download more > things (correct?). Doubt it. Here's what I do: 1. Open a Terminal window. 2. Set my working directory to "/tmp". 3. Download the PIL sources with "curl". 4. Set my working directory to the top of the unpacked PIL sources. 5. Use "python setup.py build" to build it. 6. Use "python setup.py install" to install it. 7. Start using it. Here's a transcript: % cd /tmp % curl http://effbot.org/downloads/Imaging-1.1.6.tar.gz | tar xvfz - % cd Imaging-1.1.6 % python setup.py build % sudo python setup.py install This way I can avoid getting tangled up with Fink or DarwinPorts or one of the other systems that purport to make it "easier" to install software on a Mac. Those systems were useful a few years ago, but the state of open source software, and the state of OS X, has advanced to the point where they've outlived their purpose (IMO). Enjoy! Bill From Chris.Barker at noaa.gov Tue Apr 24 18:18:30 2007 From: Chris.Barker at noaa.gov (Christopher Barker) Date: Tue, 24 Apr 2007 09:18:30 -0700 Subject: [Image-SIG] PIL on a Mac In-Reply-To: <07Apr24.083646pdt.57996@synergy1.parc.xerox.com> References: <60764.172.21.42.248.1176498386.squirrel@webmail.luther.edu> <07Apr24.083646pdt.57996@synergy1.parc.xerox.com> Message-ID: <462E2DD6.1080804@noaa.gov> Bill Janssen wrote: > You could do it the way that I do it. or even easier: >> I guess I >> had to download a MacPython in order to make Python work on my system. > > First of all, Python comes pre-installed on your Mac. It does, but it's an old version, and somewhat broken in some subtle ways. Unless you have a really slow net connection, there is no reason not to upgrade, and upgrading will get you access to binary packages that should "just work". Go to: http://pythonmac.org/packages/py25-fat/index.html download the python and PIL disk images, double click on them, and away you go. It really is that easy. > This way I can avoid getting tangled up with Fink or DarwinPorts or > one of the other systems that purport to make it "easier" to install > software on a Mac. I agree -- fink is kind of all or nothing, and if you want to write GUI apps for OS-X with Python (and not use X), you can't use fink. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (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 janssen at parc.com Tue Apr 24 20:07:10 2007 From: janssen at parc.com (Bill Janssen) Date: Tue, 24 Apr 2007 11:07:10 PDT Subject: [Image-SIG] PIL on a Mac In-Reply-To: <462E2DD6.1080804@noaa.gov> References: <60764.172.21.42.248.1176498386.squirrel@webmail.luther.edu> <07Apr24.083646pdt.57996@synergy1.parc.xerox.com> <462E2DD6.1080804@noaa.gov> Message-ID: <07Apr24.110713pdt."57996"@synergy1.parc.xerox.com> > It does, but it's an old version But not significantly different from the current version in most respects, certainly for a beginner. I've built and still use large complicated apps with lots of external Python libraries that run just fine on the system Python. > and somewhat broken in some subtle ways. Too subtle to be interesting. Bill From paulrigor at gmail.com Tue Apr 24 20:28:57 2007 From: paulrigor at gmail.com (Paul Rigor) Date: Tue, 24 Apr 2007 11:28:57 -0700 Subject: [Image-SIG] PIL on a Mac In-Reply-To: <-8392175725534668907@unknownmsgid> References: <60764.172.21.42.248.1176498386.squirrel@webmail.luther.edu> <07Apr24.083646pdt.57996@synergy1.parc.xerox.com> <462E2DD6.1080804@noaa.gov> <-8392175725534668907@unknownmsgid> Message-ID: <78771fdc0704241128o58f5657ct79e653a1a57f4524@mail.gmail.com> I sent a how-to using finkl as a sandbox to perform the installation. However, it was never sent through. Why? On 4/24/07, Bill Janssen wrote: > > > It does, but it's an old version > > But not significantly different from the current version in most > respects, certainly for a beginner. I've built and still use large > complicated apps with lots of external Python libraries that run just > fine on the system Python. > > > and somewhat broken in some subtle ways. > > Too subtle to be interesting. > > Bill > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > -- http://covertheuninsured.org/ http://www.nrdcaction.org/gwtakeaction http://www.nrdcactionfund.org/tellafriend.asp http://www.savetheinternet.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20070424/1fb65d44/attachment.htm From prigor at uci.edu Tue Apr 24 20:32:53 2007 From: prigor at uci.edu (Paul Rigor) Date: Tue, 24 Apr 2007 11:32:53 -0700 Subject: [Image-SIG] PIL on a Mac In-Reply-To: <-8392175725534668907@unknownmsgid> References: <60764.172.21.42.248.1176498386.squirrel@webmail.luther.edu> <07Apr24.083646pdt.57996@synergy1.parc.xerox.com> <462E2DD6.1080804@noaa.gov> <-8392175725534668907@unknownmsgid> Message-ID: <78771fdc0704241132m54e8c104mc316e80573b943a8@mail.gmail.com> I sent a how-to using finkl as a sandbox to perform the installation. However, it was never sent through. Why? On 4/24/07, Bill Janssen wrote: > > > It does, but it's an old version > > But not significantly different from the current version in most > respects, certainly for a beginner. I've built and still use large > complicated apps with lots of external Python libraries that run just > fine on the system Python. > > > and somewhat broken in some subtle ways. > > Too subtle to be interesting. > > Bill > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > -- http://covertheuninsured.org/ http://www.nrdcaction.org/gwtakeaction http://www.nrdcactionfund.org/tellafriend.asp http://www.savetheinternet.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20070424/c51d388d/attachment.html From export at hope.cz Wed Apr 25 07:26:43 2007 From: export at hope.cz (export at hope.cz) Date: Wed, 25 Apr 2007 07:26:43 +0200 Subject: [Image-SIG] Font colour Message-ID: <462F02B3.23747.17169ADE@export.hope.cz> An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20070425/f1446ed0/attachment.htm From export at hope.cz Wed Apr 25 11:51:12 2007 From: export at hope.cz (export at hope.cz) Date: Wed, 25 Apr 2007 11:51:12 +0200 Subject: [Image-SIG] How to set font colour that is the opposite the background colour Message-ID: <462F40B0.31537.1808BFB2@export.hope.cz> An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20070425/bd727cdb/attachment.html From Chris.Barker at noaa.gov Wed Apr 25 21:42:27 2007 From: Chris.Barker at noaa.gov (Christopher Barker) Date: Wed, 25 Apr 2007 12:42:27 -0700 Subject: [Image-SIG] Font colour In-Reply-To: <462F02B3.23747.17169ADE@export.hope.cz> References: <462F02B3.23747.17169ADE@export.hope.cz> Message-ID: <462FAF23.7010803@noaa.gov> export at hope.cz wrote: > Is there a way how to set the font colour so that it will be seen very > clearly in the picture? One way to do this in general is to put a background color behind the font. I don't see a way to do this automatically with PIL, but you can get the size of the text: font.getsize(text) => (width, height) Then draw a rectangle of that size before you draws the text. If you (for example) draw a white rectangle, then black text, you will be able to see that on top of any color. The option is to get fancy with determining the average color of th region where the text goes, then create a color that contrasts with that. However, if your text overlaps two (or more) regions of very different colors, it may be hard to automatically get a color that contrasts with all of them. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (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 export at hope.cz Thu Apr 26 09:17:04 2007 From: export at hope.cz (export at hope.cz) Date: Thu, 26 Apr 2007 09:17:04 +0200 Subject: [Image-SIG] Font colour. In-Reply-To: <462FAF23.7010803@noaa.gov> References: <462F02B3.23747.17169ADE@export.hope.cz> Message-ID: <46306E10.326.1CA1FDB8@export.hope.cz> Christopher , Thank you for your reply. Is there a way how to find out a complementary colour for an area where I will write the text, so that the text will be seen clearly?Is there a routine in PIL or in Python somewhere? Thank you for help Lad. > > export at hope.cz wrote: > > > Is there a way how to set the font colour so that it will be seen very > > clearly in the picture? > > One way to do this in general is to put a background color behind the > font. I don't see a way to do this automatically with PIL, but you can > get the size of the text: > > font.getsize(text) => (width, height) > > Then draw a rectangle of that size before you draws the text. If you > (for example) draw a white rectangle, then black text, you will be able > to see that on top of any color. > > The option is to get fancy with determining the average color of th > region where the text goes, then create a color that contrasts with > that. However, if your text overlaps two (or more) regions of very > different colors, it may be hard to automatically get a color that > contrasts with all of them. > > -Chris > > > -- > Christopher Barker, Ph.D. > Oceanographer > > Emergency Response Division > NOAA/NOS/OR&R (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 export at hope.cz Thu Apr 26 09:10:04 2007 From: export at hope.cz (export at hope.cz) Date: Thu, 26 Apr 2007 09:10:04 +0200 Subject: [Image-SIG] Font colour In-Reply-To: <462FAF23.7010803@noaa.gov> References: <462F02B3.23747.17169ADE@export.hope.cz> Message-ID: <46306C6C.26398.1C9B93C1@export.hope.cz> An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20070426/0e0ebb61/attachment.html From anewc2 at gmail.com Thu Apr 26 12:22:28 2007 From: anewc2 at gmail.com (Amos Newcombe) Date: Thu, 26 Apr 2007 06:22:28 -0400 Subject: [Image-SIG] Font colour. In-Reply-To: <46306E10.326.1CA1FDB8@export.hope.cz> References: <462F02B3.23747.17169ADE@export.hope.cz> <462FAF23.7010803@noaa.gov> <46306E10.326.1CA1FDB8@export.hope.cz> Message-ID: You find the complementary color by subtracting each color band from 255 (assuming 8-bit color). The problem with this is that if your original color is medium gray, the complementary color will be very close to it and you will get no legibility. So you have to test for this case and go to some other color, perhaps black or white. Amos On 4/26/07, export at hope.cz wrote: > > Christopher , > Thank you for your reply. > > Is there a way how to find out a complementary colour for an area where I > will write the text, so > that the text will be seen clearly?Is there a routine in PIL or in Python > somewhere? > Thank you for help > Lad. > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20070426/4a90db33/attachment.htm From paul-python at svensson.org Thu Apr 26 14:48:50 2007 From: paul-python at svensson.org (Paul Svensson) Date: Thu, 26 Apr 2007 08:48:50 -0400 (EDT) Subject: [Image-SIG] Font colour. In-Reply-To: References: <462F02B3.23747.17169ADE@export.hope.cz> <462FAF23.7010803@noaa.gov> <46306E10.326.1CA1FDB8@export.hope.cz> Message-ID: <20070426084130.T38898@familjen.svensson.org> On Thu, 26 Apr 2007, Amos Newcombe wrote: > You find the complementary color by subtracting each color band from 255 > (assuming 8-bit color). The problem with this is that if your original color > is medium gray, the complementary color will be very close to it and you > will get no legibility. So you have to test for this case and go to some > other color, perhaps black or white. Slightly better than complementing each color band, set it as far off from the background as you can; [00..7F] -> FF, [80..FF] -> 00. /Paul > Amos > > On 4/26/07, export at hope.cz wrote: >> >> Christopher , >> Thank you for your reply. >> >> Is there a way how to find out a complementary colour for an area where I >> will write the text, so >> that the text will be seen clearly?Is there a routine in PIL or in Python >> somewhere? >> Thank you for help >> Lad. >> > -- From janssen at parc.com Thu Apr 26 20:28:25 2007 From: janssen at parc.com (Bill Janssen) Date: Thu, 26 Apr 2007 11:28:25 PDT Subject: [Image-SIG] ImageStat median calculation off? Message-ID: <07Apr26.112833pdt."57996"@synergy1.parc.xerox.com> I'm running the following program over a photo: #!/usr/bin/env python import sys, os, Image, ImageStat im = Image.open(sys.argv[1]) im = im.convert("L") h = im.histogram() for i in range(len(h)): print i, h[i] s = ImageStat.Stat(h) print s.mean, s.stddev, s.extrema, s.median v = max(h) l = len([x for x in h if (x == v)]) if l > 1: print 'Multiple background colors found' else: print 'background gray shade is', h.index(v), '--', v, 'out of', sum(h) I keep getting different values for "s.median" than I get for "h.index(v)". Shouldn't they be the same value? Am I missing something? This is PIL 1.1.5 with the system Python 2.3.5 on a G4 PowerPC OS X machine. Bill From janssen at parc.com Thu Apr 26 23:01:27 2007 From: janssen at parc.com (Bill Janssen) Date: Thu, 26 Apr 2007 14:01:27 PDT Subject: [Image-SIG] ImageStat median calculation off? In-Reply-To: <07Apr26.112833pdt."57996"@synergy1.parc.xerox.com> References: <07Apr26.112833pdt."57996"@synergy1.parc.xerox.com> Message-ID: <07Apr26.140133pdt."57996"@synergy1.parc.xerox.com> > I keep getting different values for "s.median" than I get for "h.index(v)". > > Shouldn't they be the same value? Am I missing something? I guess they theoretically could be different, but in the photo I'm looking at, there are no repeated values in the histogram, so that possibility doesn't occur. Bill From douglas at paradise.net.nz Thu Apr 26 23:32:32 2007 From: douglas at paradise.net.nz (Douglas Bagnall) Date: Fri, 27 Apr 2007 09:32:32 +1200 Subject: [Image-SIG] ImageStat median calculation off? In-Reply-To: <07Apr26.112833pdt.57996@synergy1.parc.xerox.com> References: <07Apr26.112833pdt.57996@synergy1.parc.xerox.com> Message-ID: <46311A70.9080902@paradise.net.nz> Bill Janssen wrote: > > I keep getting different values for "s.median" than I get for "h.index(v)". > > Shouldn't they be the same value? Am I missing something? Isn't it *mode* that you are calculating, not median? The median would be calculated by adding up the histogram values until you have counted half the pixels, then returning the index of that point. douglas From douglas at paradise.net.nz Thu Apr 26 23:21:50 2007 From: douglas at paradise.net.nz (Douglas Bagnall) Date: Fri, 27 Apr 2007 09:21:50 +1200 Subject: [Image-SIG] Font colour In-Reply-To: <46306C6C.26398.1C9B93C1@export.hope.cz> References: <462F02B3.23747.17169ADE@export.hope.cz> <46306C6C.26398.1C9B93C1@export.hope.cz> Message-ID: <463117EE.9020204@paradise.net.nz> export at hope.cz wrote: > Is there a way how to find out a complementary colour for an area > where I will write the text, so that the text will be seen clearly? As Amos Newcombe pointed out, this is not what you really want. If you still want to try, something like this would be easiest: # complement the whole image comp = im.point(lambda x: 255 - x) # make a text mask -- a black image with white writing mask = Image.new('L', im.size, 0) font = ImageFont.load_default() draw = ImageDraw.Draw(mask) draw.text((5, 5), "hello hello", fill="white") #paste the complementary image over the original, using the text as a #mask. im.paste(comp, (0,0), mask) To follow Paul Svensson's suggestion, you would do the same, but with a different overlay image. inverse_threshold = im.point((([255]*128) + ([0]*128)) * 3) and paste that instead of the complementary image. But I think the clearest way, based on watching subtitled movies, is to have the text in a constant colour, with an outline, or shadow, or glow. So I would try instead: blur = mask.filter(ImageFilter.BLUR) im.paste((0,0,0), (0,0), blur) im.paste((255,255,255), (0,0), mask) for white writing with a black halo. Maybe black on white is better. douglas From janssen at parc.com Fri Apr 27 00:19:06 2007 From: janssen at parc.com (Bill Janssen) Date: Thu, 26 Apr 2007 15:19:06 PDT Subject: [Image-SIG] ImageStat median calculation off? In-Reply-To: <46311A70.9080902@paradise.net.nz> References: <07Apr26.112833pdt.57996@synergy1.parc.xerox.com> <46311A70.9080902@paradise.net.nz> Message-ID: <07Apr26.151914pdt."57996"@synergy1.parc.xerox.com> Aghh, yes, thanks, just dopiness on my part. More coffee needed. Bill > Bill Janssen wrote: > > > > > I keep getting different values for "s.median" than I get for "h.index(v)". > > > > Shouldn't they be the same value? Am I missing something? > > Isn't it *mode* that you are calculating, not median? The median would > be calculated by adding up the histogram values until you have counted > half the pixels, then returning the index of that point. From dave at leviathangames.com Fri Apr 27 16:54:06 2007 From: dave at leviathangames.com (Dave LeCompte) Date: Fri, 27 Apr 2007 07:54:06 -0700 Subject: [Image-SIG] Font colour References: Message-ID: <001201c788db$e8a8a410$3200000a@whale> > From: Douglas Bagnall > Subject: Re: [Image-SIG] Font colour [...] > But I think the > clearest way, based on watching subtitled movies, is to have the text > in a constant colour, with an outline, or shadow, or glow. So I would > try instead: > > blur = mask.filter(ImageFilter.BLUR) > im.paste((0,0,0), (0,0), blur) > im.paste((255,255,255), (0,0), mask) > > for white writing with a black halo. Maybe black on white is better. That's an interesting way to accomplish this - I'm not familiar with the filtering approach, so I did something similar the hard way: displayOffsets=[(-2,-2,(0,0,0)), ( 2,-2,(0,0,0)), (-2, 2,(0,0,0)), ( 2, 2,(0,0,0)), (-3, 0,(0,0,0)), ( 3, 0,(0,0,0)), ( 0,-3,(0,0,0)), ( 0, 3,(0,0,0)), ( 0, 0,(255,255,0))] for dispOff in displayOffsets: dx,dy,c=dispOff lSurf=lineFont.render(line, 1, c) pageSurf.blit(lSurf,(margin+dx,cursorPos+dy)) I was drawing text over a photographic image for use on a projection screen - this approach gives a few jaggy bits that you can see close up, but weren't a problem in pratice for me. As you can see there, I hard coded it to yellow text on a black background, which was pretty readable on most images. I was fortunate that I had a little bit of choice in the images that I was drawing, so I could select photographic backgrounds that complemented the text, rather than adapting the text to fit the photos. -Dave LeCompte From export at hope.cz Sat Apr 28 11:18:25 2007 From: export at hope.cz (export at hope.cz) Date: Sat, 28 Apr 2007 11:18:25 +0200 Subject: [Image-SIG] Font colour In-Reply-To: <463117EE.9020204@paradise.net.nz> References: <46306C6C.26398.1C9B93C1@export.hope.cz> Message-ID: <46332D81.12028.9222CC1@export.hope.cz> Douglas, Thank you for help. Now it works great if I write a text from the top, e.g. to write the text 20 pixel from left and 20 from the top. I use textpos=(20,20) But I would like to write the text to the lower left bottom, starting 30 pixels from left and 30 from the bottom. So I use textpos=(im.size[0]-30,im.size[1]-30) but it does not work. There si no text written. Can you please tell me why? Thank you Lad. > export at hope.cz wrote: > > > Is there a way how to find out a complementary colour for an area > > where I will write the text, so that the text will be seen clearly? > > As Amos Newcombe pointed out, this is not what you really want. If > you still want to try, something like this would be easiest: > > # complement the whole image > comp = im.point(lambda x: 255 - x) > > # make a text mask -- a black image with white writing > mask = Image.new('L', im.size, 0) > font = ImageFont.load_default() > draw = ImageDraw.Draw(mask) > draw.text((5, 5), "hello hello", fill="white") > > #paste the complementary image over the original, using the text as a > #mask. > im.paste(comp, (0,0), mask) > > To follow Paul Svensson's suggestion, you would do the same, but with > a different overlay image. > > inverse_threshold = im.point((([255]*128) + ([0]*128)) * 3) > > and paste that instead of the complementary image. But I think the > clearest way, based on watching subtitled movies, is to have the text > in a constant colour, with an outline, or shadow, or glow. So I would > try instead: > > blur = mask.filter(ImageFilter.BLUR) > im.paste((0,0,0), (0,0), blur) > im.paste((255,255,255), (0,0), mask) > > for white writing with a black halo. Maybe black on white is better. > > > douglas > > > > > From douglas at paradise.net.nz Sun Apr 29 02:13:53 2007 From: douglas at paradise.net.nz (Douglas Bagnall) Date: Sun, 29 Apr 2007 12:13:53 +1200 Subject: [Image-SIG] Font colour In-Reply-To: <46332D81.12028.9222CC1@export.hope.cz> References: <46306C6C.26398.1C9B93C1@export.hope.cz> <46332D81.12028.9222CC1@export.hope.cz> Message-ID: <4633E341.7040401@paradise.net.nz> Lad wrote: > But I would like to write the text to the lower left bottom, starting 30 pixels from left and 30 > from the bottom. > So I use > textpos=(im.size[0]-30,im.size[1]-30) > but it does not work. There si no text written. > Can you please tell me why? 30 pixels from the left, with the top of the text 30 pixels above the bottom, would be: textpos = (30, im.size[1]-30) What you are doing is putting the top left corner 30 pixels from the *right* side, and the text presumably runs off the edge of the picture. douglas From brad at allendev.com Mon Apr 30 22:03:30 2007 From: brad at allendev.com (Brad Allen) Date: Mon, 30 Apr 2007 15:03:30 -0500 Subject: [Image-SIG] seeking guidance on image conversion In-Reply-To: <461B5C49.8080307@unipex.it> References: <461B5C49.8080307@unipex.it> Message-ID: At 11:43 AM +0200 4/10/07, Michele Petrazzo - Unipex srl wrote: >A solution can be that already replied. >Another can be to use freeimagepy that is born because PIL doesn't >handle, like I need, the g3, g4 and multipage tiff files. >I create it, and I use it, for hylapex, a fax client that need to work >with fax files, that are in g3 and g4 format! >My old solution, like you wrote, was use the tiff gnuwin32 files, but >work with a dll a some python (ctypes) code, are better! :) Sorry for the delayed reply. That sounds interesting Michele; can you show me any source code examples of what you did with ctypes? Did you use ctypes with gnuwin32 or with some other dll? From anewc2 at gmail.com Thu Apr 26 20:43:42 2007 From: anewc2 at gmail.com (Amos Newcombe) Date: Thu, 26 Apr 2007 14:43:42 -0400 Subject: [Image-SIG] image sequences Message-ID: I can see in the docs that ImageSequence allows you to read, say an animated gif. But how do I write a sequence of images to a single animated file? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20070426/d0c23ddb/attachment.htm From slm_guzel at hotmail.com Sun Apr 29 09:28:12 2007 From: slm_guzel at hotmail.com (=?iso-8859-9?B?U0VMTUEgR9xaRUw=?=) Date: Sun, 29 Apr 2007 07:28:12 +0000 Subject: [Image-SIG] calendar program using images Message-ID: An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20070429/02edbd51/attachment.html From slm_guzel at hotmail.com Sun Apr 29 09:39:20 2007 From: slm_guzel at hotmail.com (=?iso-8859-9?B?U0VMTUEgR9xaRUw=?=) Date: Sun, 29 Apr 2007 07:39:20 +0000 Subject: [Image-SIG] writing text on image Message-ID: An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20070429/fbd8b0db/attachment.htm From rjbunting at gmail.com Sun Apr 29 09:51:49 2007 From: rjbunting at gmail.com (Robert Bunting) Date: Sun, 29 Apr 2007 15:51:49 +0800 Subject: [Image-SIG] Bug in FPX handling (in OleFileIO.py) Message-ID: I'm not sure if it's been noted before, but there's an incompatility in PIL with the FlashPix file IO and python 2.4 and up. Trying to load such a file can give OverflowError; see patch below. In the file OleFileIO.py , the function i32() uses <<. Several parts of this file then rely on the old behavior of this function to wrap round to negative values once the input is past 0xFFFFFFFF (ie 1<<32 == 0) Python 2.4 and up no longer does this, which means that the library fails to spot the end of header bytes, as it tests for == -1 and ==-2 (e.g. in loadfat()). This can result in an OverflowError being thrown, which is a problem for me when someone inputs an invalid file (I'm actually seeing this on MS word files posted to a website as images by mistake, but it could happen with a valid fpx file). A simple way to get back to the previous correct behavior would be to patch as follows: diff OleFileIO.py.new OleFileIO.py 46c46,49 < def i32(c, o = 0): < return ord(c[o])+(ord(c[o+1])<<8)+(ord(c[o+2])<<16)+(ord(c[o+3])<<24) --- > def i32(c, o = 0): > ival = ord(c[o])+(ord(c[o+1])<<8)+(ord(c[o+2])<<16)+(ord(c[o+3])<<24) > if ival > 0x80000000: > ival -= 0x100000000 > return ival but a good alternative would be to fix all the tests in the library. I guess this part of the library doesn't get exercised much :) BR, Robert Bunting. exoweb. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20070429/2d753d12/attachment.html