From neojohn75 at yahoo.com Wed Jun 1 17:46:03 2005 From: neojohn75 at yahoo.com (W. John) Date: Wed, 1 Jun 2005 08:46:03 -0700 (PDT) Subject: [Image-SIG] uchar pointer to image Message-ID: <20050601154603.94031.qmail@web90110.mail.scd.yahoo.com> Hi! This is a newbie question about PIL and Python. If I have a shared character array (buffer) that is allocated in a C++ class using "mmap". A function called 'Capture' returns a pointer to that shared area, and after a wrapper for Python I'm doing something like this: >data=mycam.Capture() >print data _0810cdbe_p_uchar How can I convert "data" (the uchar pointer) to an PIL image? Do I need to use the "fromstring" fuction? I tried something like this but is not working. >image=Image.new("L",(640,480)) >image.fromstring(data) What I'm doing wrong? Thanks. --John __________________________________ Discover Yahoo! Use Yahoo! to plan a weekend, have fun online and more. Check it out! http://discover.yahoo.com/ From 550283447739-0001 at t-online.de Wed Jun 1 21:02:36 2005 From: 550283447739-0001 at t-online.de (Oliver Albrecht) Date: Wed, 01 Jun 2005 21:02:36 +0200 Subject: [Image-SIG] Help - Palette Message-ID: <429E064C.3010904@t-online.de> Hello, (I found only the PIL(Draft Edition)(Overview)Books as Docu in the big Web.) The RGB to P Color-reduction is the best what i've ever seen. But with a weakness, the BackgroundColor is also reduced(deleted if more than 256 colors, i mean) Now i've try to make a background mask before. (After convert('P') the Palette has 1 free (unused color)Id for a Mask!?) >(1.0b1 released) > > + Added Toby J. Sargeant's quantization package. To enable > quantization, use the "palette" option to "convert": > > imOut = im.convert("P", palette=Image.ADAPTIVE) > > This can be used with "L", "P", and "RGB" images. In this > version, dithering cannot be used with adaptive palettes. > > Note: ADAPTIVE currently maps to median cut quantization > with 256 colours. The quantization package also contains > a maximum coverage quantizer, which will be supported by > future versions of PIL. This only works with ADAPTIVE=1 , i try it also with a list unsuccessful. How i can give a referent palette to convert()? >PIL 1.1.3 Book | March 12, 2002 | Fredrik Lundh, Matthew Ellis ># Note the syntax used to create the mask: > imout = im.point(lambda i: expression and 255) > Python only evaluates the portion of a logical expression as is necessary to determine the > outcome, and returns the last value examined as the result of the expression. So if the > expression above is false (0), Python does not look at the second operand, and thus > returns 0. Otherwise, it returns 255. I want make a Mask from RGB Image from only one color . I've tryed with point() unsuccessful. #maskR = source[R].point(lambda i: i == 0 and 255) #maskG = source[G].point(lambda i: i == 0 and 255) #maskB = source[B].point(lambda i: i == 132 and 255) #print mask.getcolors() #mask = Image.merge(im.mode, (maskR,maskG,maskB)) #mask = mask.convert('1') #im.paste(colour, None, mask) Thats my try(has putdata() lesser performance?): data_list=[] for r, g, b in im.getdata(): if (r,g,b) != (0,0,132): r,g,b=0,0,0 else: r,g,b=255,255,255 data_list.append((r, g, b)) im.putdata(data_list) Is that efficient enough? I want thanks for every Answers! I will also support the PIL/answers to my german py forum/wiki -- From douglas at paradise.net.nz Thu Jun 2 04:25:10 2005 From: douglas at paradise.net.nz (Douglas Bagnall) Date: Thu, 02 Jun 2005 14:25:10 +1200 Subject: [Image-SIG] uchar pointer to image In-Reply-To: <20050601154603.94031.qmail@web90110.mail.scd.yahoo.com> References: <20050601154603.94031.qmail@web90110.mail.scd.yahoo.com> Message-ID: <429E6E06.8020009@paradise.net.nz> W. John wrote: > Hi! > This is a newbie question about PIL and Python. If I > have a shared character array (buffer) that is > allocated in a C++ class using "mmap". A function > called 'Capture' returns a pointer to that shared > area, and after a wrapper for Python I'm doing > something like this: > >data=mycam.Capture() > >print data > _0810cdbe_p_uchar > > How can I convert "data" (the uchar pointer) to an PIL > image? Do I need to use the "fromstring" fuction? Image.fromstring expects a python string with the image bytes in it. In C you would do something like this: return Py_BuildValue("s#", &the_uchar_image_array, 640*480); returning a long string that would print as apparent nonsense, but would be understood by Image.fromstring. >>> image = Image.fromstring("L", (640, 480), data) There is also a Image.frombuffer, and a python buffer object, which will let you get away with less copying, but I've never used those. http://python.org/doc/2.4.1/api/bufferObjects.html http://effbot.org/imagingbook/image.htm I've also never used C++, so maybe none of this applies. douglas From fredrik at pythonware.com Thu Jun 2 10:00:18 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 2 Jun 2005 10:00:18 +0200 Subject: [Image-SIG] uchar pointer to image References: <20050601154603.94031.qmail@web90110.mail.scd.yahoo.com> Message-ID: "W. John" wrote: > This is a newbie question about PIL and Python. If I > have a shared character array (buffer) that is > allocated in a C++ class using "mmap". A function > called 'Capture' returns a pointer to that shared > area, and after a wrapper for Python I'm doing > something like this: > >data=mycam.Capture() > >print data > _0810cdbe_p_uchar > > How can I convert "data" (the uchar pointer) to an PIL > image? Python doesn't support "uchar pointers", so it's impossible to answer your question unless unless you tell us what the data object really is. Do I need to use the "fromstring" fuction? I > tried something like this but is not working. > >image=Image.new("L",(640,480)) > >image.fromstring(data) define "not working". does it give you a traceback, a segmentation violation, or garbled image data? if data is a string or buffer-compatible object, that should work (see Douglas' reply for more details). if it doesn't work, chances are that data is something else. if so, you have to figure out how to turn the contents of data into a Python string. From 550283447739-0001 at t-online.de Fri Jun 3 13:37:57 2005 From: 550283447739-0001 at t-online.de (Oliver Albrecht) Date: Fri, 03 Jun 2005 13:37:57 +0200 Subject: [Image-SIG] Answer - Help colors In-Reply-To: <429C2850.6010804@t-online.de> References: <429C2850.6010804@t-online.de> Message-ID: <42A04115.4040608@t-online.de> Hello, I not understand why nobody has answer me. because you know that i can answer me self!? >Oliver Albrecht wrote: > > - How discover the nearest color? > I want make a script to switch the colorpalette from images. > > If it give another, better way tell it me. else i will post the > completed script. That is the request/answer: if im_p.mode == "P": lut = im_p.resize((16, 16)) lut.putdata(range(256)) lut = lut.convert("RGB") palette1 = c_map.getdata() palette2 = lut.getdata() palette1 = list(palette1) palette2 = list(palette2) palette=set(palette1) ## not common colors from palette2 palette.difference_update(palette2) ocolors=set(palette2) ## not common colors from palette1 ocolors.difference_update(palette1) ## give the colors a index palette = [(palette1.index(color), color) for color in palette] for (cr,cg,cb) in ocolors: opal_dict = {} for item in palette: r,g,b=item[1] opal_dict[abs(r-cr)+abs(g-cg)+abs(b-cb)]=item[0] ## the nearest color palette2[palette2.index((cr,cg,cb))]= palette1[opal_dict[min(opal_dict.keys())]] for colorID in xrange(len(palette2)): palette2[colorID]=palette1.index(palette2[colorID]) im_p.putpalette(c_map_pl) im_p=im_p.point(palette2) ##PIL(book)Returns a copy of the image #where each pixel has been mapped #through the given table. > I want make a Mask from RGB Image from only one color . > Thats my try(has putdata() lesser performance?): [..snipped..] > Is that efficient enough? i mean this is better: def MakeMask(im): data_list=[] bground=im.getpixel((0,0)) for r, g, b in im.getdata(): if (r,g,b) != bground: i=0 else: i=255 data_list.append(i) im = Image.new('1',im.size) im.putdata(data_list) return im -- From swiftset at gmail.com Sat Jun 4 23:34:16 2005 From: swiftset at gmail.com (Alex Gittens) Date: Sat, 4 Jun 2005 16:34:16 -0500 Subject: [Image-SIG] freetype integration example? Message-ID: Could you point me to example code of using PIL to draw FreeType glyphs? Thanks, Alex -- Mathematicians hate thinking about foundations. Whenever a famous open problem turns out to be equivalent to the Continuum Hypothesis, it's like a family member died, or worse joined a cult. - (http://www.arsmathematica.net/archives/2005/05/24/programming-language-and-logic-links/) From carroll at tjc.com Sun Jun 5 04:46:02 2005 From: carroll at tjc.com (Terry Carroll) Date: Sat, 4 Jun 2005 19:46:02 -0700 (PDT) Subject: [Image-SIG] Copying EXIF data from one file or PIL image to another? Message-ID: Can anyone tell me if it's fairly easy to copy a JPEG file's EXIF data to another file. Even better would be if this is doable in PIL. My basic problem: I've written a small program that reads a JPEG image in PIL, and creates a copy that is slightly modified (it overlays the image with a datestamp taken from the EXIF data), and saves it as a new file. It all works swimmingly well, except that the ne file has no EXIF data. I'd like to copy the original image's EXIF data to the new image. From richard at reticulatus.plus.com Sun Jun 5 11:04:02 2005 From: richard at reticulatus.plus.com (Richard Townsend) Date: Sun, 05 Jun 2005 10:04:02 +0100 Subject: [Image-SIG] Copying EXIF data from one file or PIL image to another? Message-ID: <42A2C002.9060709@reticulatus.plus.com> Not sure about PIL, but Gene Cash has a Python module for handling EXIF data: http://home.cfl.rr.com/genecash/digital_camera.html -- Richard Townsend From p.f.moore at gmail.com Sun Jun 5 16:07:05 2005 From: p.f.moore at gmail.com (Paul Moore) Date: Sun, 5 Jun 2005 15:07:05 +0100 Subject: [Image-SIG] Copying EXIF data from one file or PIL image to another? In-Reply-To: References: Message-ID: <79990c6b050605070757727d65@mail.gmail.com> On 6/5/05, Terry Carroll wrote: > Can anyone tell me if it's fairly easy to copy a JPEG file's EXIF data to > another file. Even better would be if this is doable in PIL. > > My basic problem: > > I've written a small program that reads a JPEG image in PIL, and creates a > copy that is slightly modified (it overlays the image with a datestamp > taken from the EXIF data), and saves it as a new file. It all works > swimmingly well, except that the ne file has no EXIF data. I'd like to > copy the original image's EXIF data to the new image. You can *read* EXIF information via the _getexif() method of the image. Use the KEYS dictionary in the ExifTags module to map numeric keys to friendly names. For example, >>> d = dict((ExifTags.TAGS[k], v) for k, v in im._getexif().items()) >>> d['DateTimeOriginal'] '2002:08:07 17:07:59' Unfortunately, I don't know of a way to *write* EXIF information with PIL. Hope this helps (a bit) Paul. From maxerickson at gmail.com Sun Jun 5 14:56:53 2005 From: maxerickson at gmail.com (Max Erickson) Date: Sun, 5 Jun 2005 12:56:53 +0000 (UTC) Subject: [Image-SIG] Copying EXIF data from one file or PIL image to another? References: Message-ID: Terry Carroll wrote in news:Pine.LNX.4.44.0506041940230.12716-100000 at mauve.rahul.net: > Can anyone tell me if it's fairly easy to copy a JPEG file's EXIF > data to another file. Even better would be if this is doable in > PIL. > Jhead should be able to transfer the exif information: http://www.sentex.net/~mwandel/jhead/ Alternatively, see: http://mail.python.org/pipermail/image-sig/2004-September/002931.html for a patch that adds support for writing raw exif headers to pil. max From carroll at tjc.com Mon Jun 6 02:46:46 2005 From: carroll at tjc.com (Terry Carroll) Date: Sun, 5 Jun 2005 17:46:46 -0700 (PDT) Subject: [Image-SIG] Copying EXIF data from one file or PIL image to another? In-Reply-To: <42A2C002.9060709@reticulatus.plus.com> Message-ID: On Sun, 5 Jun 2005, Richard Townsend wrote: > Not sure about PIL, but Gene Cash has a Python module for handling EXIF > data: > > http://home.cfl.rr.com/genecash/digital_camera.html Thanks, Richard. I'm already using that -- that's how I'm getting the EXIF data -- but it's read-only, there's no way to take its data and write to another JPEG file. On Sun, 5 Jun 2005, Paul Moore wrote: > You can *read* EXIF information via the _getexif() method of the > image.... > [example snipped] > Unfortunately, I don't know of a way to *write* EXIF information with > PIL. Yeah, that's what it looks like to me. I tried im0.app = im.app where im is the source image amd im0 is my destination image; that adds the appropriate EXIF data to the PIL Image object, but it doesn't get written out to the file when I do an im0.save(). This is still helpful information, though. I had no idea that PIL supported EXIF, and I'd rather use PIL's support than load in Gene Cash's module: one less dependancy. On Sun, 5 Jun 2005, Max Erickson wrote: > Jhead should be able to transfer the exif information: > http://www.sentex.net/~mwandel/jhead/ > > Alternatively, see: > http://mail.python.org/pipermail/image-sig/2004-September/002931.html > for a patch that adds support for writing raw exif headers to pil. Thanks. I think I'll go with JHead. This program is mostly for personal use, but I may have one or two friends who may find it useful, too. I can put in a "Preserve EXIF (requires JHEAD)" checkbox, so that it's useful w/o it. It's probably easier to copy JHead along with my program than it is to patch PIL. Thanks to all responses. From philou at philou.ch Mon Jun 6 10:11:47 2005 From: philou at philou.ch (Philippe Strauss) Date: Mon, 6 Jun 2005 10:11:47 +0200 Subject: [Image-SIG] multiline text Message-ID: <20050606081147.GA4784@philou.ch> Hello, when I pass a multiline string (the EOL character being '\n') to the text() method of a Draw object, the result is displayed on a single line with square boxes in place of the newline. is it a feature or a bug? I'm not subscribed, please answer directly, thank you! -- Philippe Strauss http://philou.ch/ From 550283447739-0001 at t-online.de Tue Jun 7 00:35:05 2005 From: 550283447739-0001 at t-online.de (Oliver Albrecht) Date: Tue, 07 Jun 2005 00:35:05 +0200 Subject: [Image-SIG] Help Experimental (palette) Message-ID: <42A4CF99.30004@t-online.de> Hello again, I love PIL and would like support this.(,no matter whether it is commercial) Sorry if my last messages was bad. I've experimented with palette.save/load options and i extended the palette.save/load functions. It is not important, but it can be attained without large expenditure. The Gimp and PaintShopP palette files are very similar. I mean can bring in it in the next version!? # add some psuedocolour palettes as well ( successfully tested with Gimp2.2 and PSP9.0) example: def save(self, fp , art="GIMP"): # (experimental) save palette to text file des="" if self.rawmode: raise ValueError("palette contains raw palette data") if type(fp) == type(""): if art and art[:4] == "GIMP": fp = open(fp, "wb") fp.write("%s\n# Mode: %s\n" % ("GIMP Palette",self.mode)) des='" %i" % i' ##FIXME color description elif art[:4] == "JASC": fp = open(fp, "w") fp.write("JASC-PAL\n0100\n256\n") else: raise ValueError, "wrong palette type" for i in range(256): fp.write("%d %d %d" % (self.palette[i] ,self.palette[i+256], self.palette[i+512])) fp.write("%s\n" % eval(des)) fp.close() And again a big Question: How i can load the palette from FLI/FLC files, or is it experimental and/or not yet supported? The palette of each band is only gray. Sorry if my english is to bad. I've attached the sample Modul JascPaletteFile -- input -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: JascPaletteFile.py Url: http://mail.python.org/pipermail/image-sig/attachments/20050607/5bd7ff0c/JascPaletteFile.ksh From a_wilson at mit.edu Tue Jun 7 10:45:25 2005 From: a_wilson at mit.edu (Andrew Wilson) Date: Tue, 07 Jun 2005 10:45:25 +0200 Subject: [Image-SIG] 16 Grayscale tiff Message-ID: <42A55EA5.3070401@mit.edu> Hello, I'm trying to save load an unsigned 16 bit array from numarray into a grayscale 16-bit tiff, I tried using Image.fromstring("I;16",...), but I get an error "illegal conversion" within img.convert('RGB'). So it looks like only 16 bit RGB files are supported? Thanks Andrew From fredrik at pythonware.com Thu Jun 9 09:22:16 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 9 Jun 2005 09:22:16 +0200 Subject: [Image-SIG] 16 Grayscale tiff References: <42A55EA5.3070401@mit.edu> Message-ID: Andrew Wilson wrote: > I'm trying to save load an unsigned 16 bit array from numarray into > a grayscale 16-bit tiff, I tried using Image.fromstring("I;16",...), > but I get an error "illegal conversion" within img.convert('RGB'). So > it looks like only 16 bit RGB files are supported? does img.convert("I").convert("RGB") work better? From franz at trispen.com Thu Jun 9 14:20:23 2005 From: franz at trispen.com (Franz Struwig) Date: Thu, 09 Jun 2005 14:20:23 +0200 Subject: [Image-SIG] PDF to Image conversion Message-ID: Greetings, Does anyone know of an elegant method to convert a PDF to an image...possibly using PIL? Thanks, Franz From kevin at cazabon.com Thu Jun 9 19:08:58 2005 From: kevin at cazabon.com (kevin@cazabon.com) Date: Thu, 9 Jun 2005 19:08:58 +0200 Subject: [Image-SIG] PDF to Image conversion References: Message-ID: <028e01c56d15$ed03d7c0$640aa8c0@duallie> You'll need a RIP to do this (Raster Image Processor - to convert vector graphics to raster graphics), and unfortunately PIL isn't a RIP. However, you may want to look at GhostScript - a GPL postscript RIP (it does PDF's now too). It's cross-platform too, and scriptable. http://www.gnu.org/software/ghostscript/ghostscript.html Kevin ----- Original Message ----- From: "Franz Struwig" To: Sent: Thursday, June 09, 2005 2:20 PM Subject: [Image-SIG] PDF to Image conversion > Greetings, > > Does anyone know of an elegant method to convert a PDF to an > image...possibly using PIL? > > Thanks, > Franz > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > > > From marc.cuculiere.cs at eurocontrol.int Thu Jun 9 10:14:49 2005 From: marc.cuculiere.cs at eurocontrol.int (CUCULIERE Marc (CS)) Date: Thu, 9 Jun 2005 10:14:49 +0200 Subject: [Image-SIG] Install problems on Fedora Core release 2 Message-ID: Hello, History, I tryed to install version 1.1.4 of PIL but the install did not work : NameError: name 'EXTRA_COMPILE_ARGS' is not defined" (@PIL124) I looked a this problem and a solution was proposed only on MAC OS X I called my client who told me to try to install the latest version (1.1.5) It didn't work, the logs are below (mcuculie is simply user, not a super/powerfull user) mcuculie at zutton ~/ZUTTON/Imaging-1.1.5$ python setup.py install running install running build running build_py creating build creating build/lib.linux-i686-2.3 copying PIL/ArgImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/BdfFontFile.py -> build/lib.linux-i686-2.3 copying PIL/BmpImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/BufrStubImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/ContainerIO.py -> build/lib.linux-i686-2.3 copying PIL/CurImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/DcxImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/EpsImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/ExifTags.py -> build/lib.linux-i686-2.3 copying PIL/FitsStubImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/FliImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/FontFile.py -> build/lib.linux-i686-2.3 copying PIL/FpxImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/GbrImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/GdImageFile.py -> build/lib.linux-i686-2.3 copying PIL/GifImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/GimpGradientFile.py -> build/lib.linux-i686-2.3 copying PIL/GimpPaletteFile.py -> build/lib.linux-i686-2.3 copying PIL/GribStubImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/Hdf5StubImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/IcnsImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/IcoImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/Image.py -> build/lib.linux-i686-2.3 copying PIL/ImageChops.py -> build/lib.linux-i686-2.3 copying PIL/ImageColor.py -> build/lib.linux-i686-2.3 copying PIL/ImageDraw.py -> build/lib.linux-i686-2.3 copying PIL/ImageEnhance.py -> build/lib.linux-i686-2.3 copying PIL/ImageFile.py -> build/lib.linux-i686-2.3 copying PIL/ImageFileIO.py -> build/lib.linux-i686-2.3 copying PIL/ImageFilter.py -> build/lib.linux-i686-2.3 copying PIL/ImageFont.py -> build/lib.linux-i686-2.3 copying PIL/ImageGL.py -> build/lib.linux-i686-2.3 copying PIL/ImageGrab.py -> build/lib.linux-i686-2.3 copying PIL/ImageOps.py -> build/lib.linux-i686-2.3 copying PIL/ImagePalette.py -> build/lib.linux-i686-2.3 copying PIL/ImagePath.py -> build/lib.linux-i686-2.3 copying PIL/ImageSequence.py -> build/lib.linux-i686-2.3 copying PIL/ImageStat.py -> build/lib.linux-i686-2.3 copying PIL/ImageTk.py -> build/lib.linux-i686-2.3 copying PIL/ImageTransform.py -> build/lib.linux-i686-2.3 copying PIL/ImageWin.py -> build/lib.linux-i686-2.3 copying PIL/ImImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/ImtImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/IptcImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/JpegImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/McIdasImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/MicImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/MpegImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/MspImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/OleFileIO.py -> build/lib.linux-i686-2.3 copying PIL/PaletteFile.py -> build/lib.linux-i686-2.3 copying PIL/PalmImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/PcdImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/PcfFontFile.py -> build/lib.linux-i686-2.3 copying PIL/PcxImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/PdfImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/PixarImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/PngImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/PpmImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/PsdImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/PSDraw.py -> build/lib.linux-i686-2.3 copying PIL/SgiImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/SpiderImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/SunImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/TarIO.py -> build/lib.linux-i686-2.3 copying PIL/TgaImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/TiffImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/TiffTags.py -> build/lib.linux-i686-2.3 copying PIL/WalImageFile.py -> build/lib.linux-i686-2.3 copying PIL/WmfImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/XbmImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/XpmImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/XVThumbImagePlugin.py -> build/lib.linux-i686-2.3 copying PIL/__init__.py -> build/lib.linux-i686-2.3 running build_ext building '_imaging' extension creating build/temp.linux-i686-2.3 creating build/temp.linux-i686-2.3/libImaging gcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -g -pipe -m32 -march=i386 -mtune=pentium4 -D_GNU_SOURCE -fPIC -fPIC -DHAVE_LIBJPEG -DHAVE_LIBZ -I/usr/include/freetype2 -IlibImaging -I/usr/include -I/usr/local/include -I/usr/include/python2.3 -c libImaging/Blend.c -o build/temp.linux-i686-2.3/libImaging/Blend.o cc1: error: invalid option `tune=pentium4' error: command 'gcc' failed with exit status 1 Can someone help me ? Thanks a lot, Marc. ____ This message and any files transmitted with it are legally privileged and intended for the sole use of the individual(s) or entity to whom they are addressed. If you are not the intended recipient, please notify the sender by reply and delete the message and any attachments from your system. Any unauthorised use or disclosure of the content of this message is strictly prohibited and may be unlawful. Nothing in this e-mail message amounts to a contractual or legal commitment on the part of EUROCONTROL unless it is confirmed by appropriately signed hard copy. Any views expressed in this message are those of the sender. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20050609/7fca1b66/attachment.html From franz at trispen.com Fri Jun 10 10:47:00 2005 From: franz at trispen.com (Franz Struwig) Date: Fri, 10 Jun 2005 10:47:00 +0200 Subject: [Image-SIG] Feature extraction Message-ID: Greetings all, I'm trying to isolate characters on an image and obtain each character's center of gravity. This is quite a tough task when using strange fonts and italics, since letters overlap constantly, and bad image quality makes it really hard. Does anyone know about an algorithm that can be used for this kind of feature extraction process? Thanks, Franz From klimek at grc.nasa.gov Fri Jun 10 16:21:24 2005 From: klimek at grc.nasa.gov (Bob Klimek) Date: Fri, 10 Jun 2005 10:21:24 -0400 Subject: [Image-SIG] Feature extraction In-Reply-To: References: Message-ID: <42A9A1E4.6070609@grc.nasa.gov> Franz Struwig wrote: >Greetings all, > >I'm trying to isolate characters on an image and obtain each character's >center of gravity. > >This is quite a tough task when using strange fonts and italics, since >letters overlap constantly, and bad image quality makes it really hard. > >Does anyone know about an algorithm that can be used for this kind of >feature extraction process? > > I'm don't think PIL has anything of the sort but I believe Numarray's nd_image module has some basic segmentation and labeling, which might do what you need, or perhaps could be a starting point for you to add some capability. Bob From rzantow at ntelos.net Fri Jun 10 16:59:18 2005 From: rzantow at ntelos.net (rzed) Date: Fri, 10 Jun 2005 10:59:18 -0400 Subject: [Image-SIG] Is there an image editor that interfaces with PIL? Message-ID: <42A9AAC6.7000604@ntelos.net> Does anyone know of an image editor that interfaces with PIL nicely? What I mean is one that could directly load PIL objects, and one whose buffer(s) PIL could operate on pretty directly. If not, I suppose I could try to make one, but if one already exists, I'd like to try that first. What I have in mind is essentially just a front end for PIL operations, with some manual draw/paint capability; ideally, this would be written in and extendible with Python. So is there something like this already? From felixg at techunix.technion.ac.il Fri Jun 10 17:39:42 2005 From: felixg at techunix.technion.ac.il (Felix Goldberg) Date: Fri, 10 Jun 2005 18:39:42 +0300 (IDT) Subject: [Image-SIG] Feature extraction In-Reply-To: References: Message-ID: You can google for "shape descriptors" and find some pertinent information. HTH, Felix. --------------------------------------- Felix Goldberg, M.Sc. felixg at tx.technion.ac.il www.technion.ac.il/~felixg On Fri, 10 Jun 2005, Franz Struwig wrote: > Greetings all, > > I'm trying to isolate characters on an image and obtain each character's > center of gravity. > > This is quite a tough task when using strange fonts and italics, since > letters overlap constantly, and bad image quality makes it really hard. > > Does anyone know about an algorithm that can be used for this kind of > feature extraction process? > > Thanks, > Franz > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > From gwidion at mpc.com.br Fri Jun 10 18:55:39 2005 From: gwidion at mpc.com.br (Joao S. O. Bueno Calligaris) Date: Fri, 10 Jun 2005 13:55:39 -0300 Subject: [Image-SIG] Is there an image editor that interfaces with PIL? In-Reply-To: <42A9AAC6.7000604@ntelos.net> References: <42A9AAC6.7000604@ntelos.net> Message-ID: <200506101355.39612.gwidion@mpc.com.br> On Friday 10 June 2005 11:59, rzed wrote: > Does anyone know of an image editor that interfaces with PIL > nicely? What I mean is one that could directly load PIL objects, > and one whose buffer(s) PIL could operate on pretty directly. > > If not, I suppose I could try to make one, but if one already > exists, I'd like to try that first. > > What I have in mind is essentially just a front end for PIL > operations, with some manual draw/paint capability; ideally, this > would be written in and extendible with Python. So is there > something like this already? There is the GIMP! Tehre is Pygimp - the python bindings for the GIMP It can operate on iamges with methods of its own -and if you prefer, you can throw in PIL as well for further editing. > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig From jwt at OnJapan.net Sat Jun 11 03:08:00 2005 From: jwt at OnJapan.net (Jim Tittsler) Date: Sat, 11 Jun 2005 10:08:00 +0900 Subject: [Image-SIG] Install problems on Fedora Core release 2 In-Reply-To: References: Message-ID: <20050611010800.GB303@server.onjapan.net> On Thu, Jun 09, 2005 at 10:14:49AM +0200, CUCULIERE Marc (CS) wrote: > gcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -g -pipe -m32 -march=i386 > -mtune=pentium4 -D_GNU_SOURCE -fPIC -fPIC -DHAVE_LIBJPEG -DHAVE_LIBZ > -I/usr/include/freetype2 -IlibImaging -I/usr/include -I/usr/local/include > -I/usr/include/python2.3 -c libImaging/Blend.c -o > build/temp.linux-i686-2.3/libImaging/Blend.o > cc1: error: invalid option `tune=pentium4' > error: command 'gcc' failed with exit status 1 What version of gcc are you using? You could try treating the symptom by removing the -mtune=pentium4 option from your /usr/lib/python*/config/Makefile -- Jim Tittsler http://www.OnJapan.net/ GPG: 0x01159DB6 Python Starship http://Starship.Python.net/ Ringo MUG Tokyo http://www.ringo.net/rss.html From dylan.moreland at gmail.com Sun Jun 12 23:44:12 2005 From: dylan.moreland at gmail.com (Dylan Moreland) Date: Sun, 12 Jun 2005 17:44:12 -0400 Subject: [Image-SIG] Converting from numarray to PIL Message-ID: Hello all, I'm working with some large numarrays of astronomical data (1000 by 1000 pixels) that I want to quickly transform into grayscale images for use in my wxPython app. I've tried drawing them using canvas methods in both PIL and wx, scaling the values from their original range to [0, 255] for use as the colors, but this is too slow for my application. I see from http://effbot.org/zone/pil-numpy.htm That it is possible to directly transform a numarray into an Image, but there isn't much documentation about the typecodes involved. How would I transform my array into one that, when loaded into PIL, displays a range of grays? Thanks! Dylan Moreland University of Michigan From fredrik at pythonware.com Mon Jun 13 07:57:58 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 13 Jun 2005 07:57:58 +0200 Subject: [Image-SIG] Converting from numarray to PIL References: Message-ID: Dylan Moreland wrote: > I'm working with some large numarrays of astronomical data (1000 by > 1000 pixels) that I want to quickly transform into grayscale images > for use in my wxPython app. I've tried drawing them using canvas > methods in both PIL and wx, scaling the values from their original > range to [0, 255] for use as the colors, but this is too slow for my > application. have you tried im.putdata(array, scale, offset) ? > I see from > > http://effbot.org/zone/pil-numpy.htm > > That it is possible to directly transform a numarray into an Image, > but there isn't much documentation about the typecodes involved. How > would I transform my array into one that, when loaded into PIL, > displays a range of grays? map the values to the 0-255 range, turn it into an UnsignedInt8 array, and pass the result to the "array2image" function. this gives you a grayscale PIL image (mode "L"). From fredrik at pythonware.com Mon Jun 13 12:04:52 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 13 Jun 2005 12:04:52 +0200 Subject: [Image-SIG] Install problems on Fedora Core release 2 References: Message-ID: "CUCULIERE Marc (CS)" wrote: > I tryed to install version 1.1.4 of PIL but the install did not work : > NameError: name 'EXTRA_COMPILE_ARGS' is not defined" (@PIL124) > I looked a this problem and a solution was proposed only on MAC OS X the patch on this page works on all platforms: http://effbot.org/zone/pil-errata-114.htm you might have misinterpreted the comment; it was a OS X-specific change that broke the script (under certain conditions), but the script is equally broken on all platforms that happens to have freetype but not tk. > I called my client who told me to try to install the latest version (1.1.5) > It didn't work, the logs are below > (mcuculie is simply user, not a super/powerfull user) > gcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -g -pipe -m32 -march=i386 > -mtune=pentium4 -D_GNU_SOURCE -fPIC -fPIC -DHAVE_LIBJPEG -DHAVE_LIBZ > -I/usr/include/freetype2 -IlibImaging -I/usr/include -I/usr/local/include > -I/usr/include/python2.3 -c libImaging/Blend.c -o > build/temp.linux-i686-2.3/libImaging/Blend.o > cc1: error: invalid option `tune=pentium4' > error: command 'gcc' failed with exit status 1 the gcc options are determined by the Python setup procedure, so it looks like you've built Python on one machine, and is trying to build PIL on a machine that has a different (older?) version of gcc. make sure you're using the gcc version shipped with FC2 (or a later version), or see Jim's mail for a workaround. From fredrik at pythonware.com Wed Jun 15 15:43:04 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 15 Jun 2005 15:43:04 +0200 Subject: [Image-SIG] pil ten year anniversary Message-ID: just fyi: $ cd pil $ grep 1995-06 */*.c libImaging/Convert.c: * 1995-06-15 fl created libImaging/Except.c: * 1995-06-15 fl Created libImaging/Geometry.c: * 1995-06-15 fl Created libImaging/Histo.c: * 1995-06-15 fl Created. libImaging/Storage.c: * 1995-06-15 fl Created thanks to everyone who's used PIL for cool stuff for the last decade, and everyone who's contributed cool stuff to PIL ! cheers /F From guillaume.proux at scala.com Wed Jun 15 17:53:52 2005 From: guillaume.proux at scala.com (Guillaume Proux) Date: Thu, 16 Jun 2005 00:53:52 +0900 Subject: [Image-SIG] pil ten year anniversary In-Reply-To: References: Message-ID: <42B04F10.9090709@scala.com> Congrats! To infinity and beyond :) cheers, G Fredrik Lundh wrote: > just fyi: > > $ cd pil > $ grep 1995-06 */*.c > libImaging/Convert.c: * 1995-06-15 fl created > libImaging/Except.c: * 1995-06-15 fl Created > libImaging/Geometry.c: * 1995-06-15 fl Created > libImaging/Histo.c: * 1995-06-15 fl Created. > libImaging/Storage.c: * 1995-06-15 fl Created > > thanks to everyone who's used PIL for cool stuff for the last decade, > and everyone who's contributed cool stuff to PIL ! > > cheers /F > From klimek at grc.nasa.gov Wed Jun 15 18:50:52 2005 From: klimek at grc.nasa.gov (Bob Klimek) Date: Wed, 15 Jun 2005 12:50:52 -0400 Subject: [Image-SIG] pil ten year anniversary In-Reply-To: References: Message-ID: <42B05C6C.7080302@grc.nasa.gov> It's just getting better and better! Congrats! And thanks for all your work, Bob Fredrik Lundh wrote: >just fyi: > >$ cd pil >$ grep 1995-06 */*.c >libImaging/Convert.c: * 1995-06-15 fl created >libImaging/Except.c: * 1995-06-15 fl Created >libImaging/Geometry.c: * 1995-06-15 fl Created >libImaging/Histo.c: * 1995-06-15 fl Created. >libImaging/Storage.c: * 1995-06-15 fl Created > >thanks to everyone who's used PIL for cool stuff for the last decade, >and everyone who's contributed cool stuff to PIL ! > >cheers /F > > > >_______________________________________________ >Image-SIG maillist - Image-SIG at python.org >http://mail.python.org/mailman/listinfo/image-sig > > > From yarglags at eircom.net Fri Jun 17 06:22:09 2005 From: yarglags at eircom.net (Peter Dempsey) Date: Fri, 17 Jun 2005 05:22:09 +0100 Subject: [Image-SIG] Converting to zebra (ZPL) format Message-ID: <200506170522.10137.yarglags@eircom.net> Hi folks, I'm a newbie to python so please be gentle. I want to convert an image to a format suitable for use in a Zebra label printer. The data sent to the printer consists of a string of hex characters. Each byte converts to a binary set of dots on the label. FF becomes 11111111 A5 becomes 10100101 So a string like this becomes a right-angle triangle... 18,3^m F00000FF0000FFF000FFFF00FFFFF0FFFFFF The 18 says how many bytes in the image, 3 says how many bytes wide the image is. So the string above becomes... F00000 -> 111100000000000000000000 FF0000 -> 111111110000000000000000 FFF000 -> 111111111111000000000000 FFFF00 -> 111111111111111100000000 FFFFF0 -> 111111111111111111110000 FFFFFF -> 111111111111111111111111 I'm sure it's a simple task, I mean, the image is converted to a hex representation of the raw image. I've had some success doing it the hard way with python, importing a pcx image and going through it byte by byte but I'm sure there's an easier way. Any suggestions would be super. I don't have my code here at home. I can post it tomorrow if it helps. Thanks, Peter From fredrik at pythonware.com Fri Jun 17 09:40:43 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 17 Jun 2005 09:40:43 +0200 Subject: [Image-SIG] Converting to zebra (ZPL) format References: <200506170522.10137.yarglags@eircom.net> Message-ID: Peter Dempsey wrote: > Hi folks, I'm a newbie to python so please be gentle. > > I want to convert an image to a format suitable for use in a Zebra label > printer. The data sent to the printer consists of a string of hex characters. > Each byte converts to a binary set of dots on the label. > > FF becomes 11111111 > A5 becomes 10100101 > > So a string like this becomes a right-angle triangle... > > 18,3^m > F00000FF0000FFF000FFFF00FFFFF0FFFFFF > > The 18 says how many bytes in the image, 3 says how many bytes wide the image > is. So the string above becomes... > > F00000 -> 111100000000000000000000 > FF0000 -> 111111110000000000000000 > FFF000 -> 111111111111000000000000 > FFFF00 -> 111111111111111100000000 > FFFFF0 -> 111111111111111111110000 > FFFFFF -> 111111111111111111111111 > > I'm sure it's a simple task, I mean, the image is converted to a hex > representation of the raw image. > > I've had some success doing it the hard way with python, importing a pcx image > and going through it byte by byte but I'm sure there's an easier way. > > Any suggestions would be super. how about: import Image # # step 1) convert example to pil image data = ( "111100000000000000000000", "111111110000000000000000", "111111111111000000000000", "111111111111111100000000", "111111111111111111110000", "111111111111111111111111", ) height = len(data) width = len(data[0]) im = Image.new("1", (width, height), 0) # convert data to list of values pixels = [] for row in data: pixels.extend([1-int(ch) for ch in row]) im.putdata(pixels) # # step 2) convert it back to a hex string data = im.tostring("raw", "1;I") size = len(data) data = ["%02X" % ord(byte) for byte in data] print "%d,%d^m" % (size, (im.size[0]+7)/8) print "".join(data) # end things to notice: - step 1 can of course be replaced with some other way to create a mode "1" image - mode "1" images treat "1" as white and "0" as black. - the tostring arguments are a bit magical. some info can be found here: http://effbot.org/imagingbook/decoder.htm - [blah for blah in blah] is a list comprehension. if you're using Python 2.4, you can omit the brackets (which turns it into a generator expression, but the result is the same) - (blah+7)/8 converts the number of pixels to a number of bytes, rounding up to the nearest byte. to be future safe, you might wish to use "//" instead of "/". From LISTSERV at LISTSERV.MSN.COM Fri Jun 17 10:41:22 2005 From: LISTSERV at LISTSERV.MSN.COM (Microsoft LISTSERV Server (14.3)) Date: Fri, 17 Jun 2005 04:41:22 -0400 Subject: [Image-SIG] Extended Mail Message-ID: > Encrypted message is available. Unknown command - "ENCRYPTED". Try HELP. Summary of resource utilization ------------------------------- CPU time: 0.000 sec Device I/O: 4 Overhead CPU: 0.000 sec Paging I/O: 0 CPU model: 933MHz Pentium III 256k (1152M) Job origin: image-sig at PYTHON.ORG From mbirot at u-prod.com Fri Jun 17 15:01:10 2005 From: mbirot at u-prod.com (marc birot) Date: Fri, 17 Jun 2005 21:01:10 +0800 Subject: [Image-SIG] Converting CMYK JPG image to RGB Message-ID: <42B2C996.9020604@u-prod.com> Hello, I'm trying to convert CMYK Jpg files to RGB Jpg files using (Image.open("cmyk_image.jpg").convert("RGB"))... The result shows very wrong colours. After checking the Image-SIG archives (Aug 2004) i found the following : "...Older versions of Photoshop generated broken CMYK files, and PIL attempts to compensate for this. try commenting out the following lines in PIL/JpegImagePlugin.py, and let me know if it helps: if self.mode == "CMYK" and self.info.has_key("adobe"): rawmode = "CMYK;I" # Photoshop 2.5 is broken! ..." Well, i tried and it does not work. The result i get is close to a 'negative' of the original picture ( not too close). Any suggestion to help on this problem ? :) Marc From kevin at cazabon.com Fri Jun 17 16:40:41 2005 From: kevin at cazabon.com (kevin@cazabon.com) Date: Fri, 17 Jun 2005 07:40:41 -0700 Subject: [Image-SIG] Converting CMYK JPG image to RGB References: <42B2C996.9020604@u-prod.com> Message-ID: <004101c5734a$89496570$6a44f4cc@cem.creo.com> I know the problem you mention, but I also thought that a recent version of PIL fixed it... I could be wrong though. However - the other option would be to use ICC profiles to do color conversion. If you want REALLY accurate conversion, this is the way to go. I wrote a wrapper module called pyCMS that uses the littleCMS library to do ICC conversions. See: http://www.cazabon.com/pyCMS Kevin. ----- Original Message ----- From: "marc birot" To: Sent: Friday, June 17, 2005 6:01 AM Subject: [Image-SIG] Converting CMYK JPG image to RGB > Hello, > > I'm trying to convert CMYK Jpg files to RGB Jpg files using > (Image.open("cmyk_image.jpg").convert("RGB"))... > The result shows very wrong colours. > > After checking the Image-SIG archives (Aug 2004) i found the following : > > "...Older versions of Photoshop generated broken CMYK files, and PIL > attempts to compensate for this. try commenting out the following lines > in PIL/JpegImagePlugin.py, and let me know if it helps: > if self.mode == "CMYK" and self.info.has_key("adobe"): > rawmode = "CMYK;I" # Photoshop 2.5 is broken! ..." > > Well, i tried and it does not work. The result i get is close to a > 'negative' of the original picture ( not too close). > > Any suggestion to help on this problem ? :) > > Marc > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > > From gwidion at mpc.com.br Sat Jun 18 03:40:46 2005 From: gwidion at mpc.com.br (Joao S. O. Bueno Calligaris) Date: Fri, 17 Jun 2005 22:40:46 -0300 Subject: [Image-SIG] Converting to zebra (ZPL) format In-Reply-To: <200506170522.10137.yarglags@eircom.net> References: <200506170522.10137.yarglags@eircom.net> Message-ID: <200506172240.47031.gwidion@mpc.com.br> Hi Peter, despite Fredik's lengthy and carefull answer, I think that is not what you were asking for - his program is suitable to print images inpout inline inside a Python program as sequences of 0 and 1's. But I think you were asking for a way to print a generic image read from a disk file. I can code that for you, if you wish so - just write me if no one else mailed yu a complete answer, and tell me more details about the images you want to print, maximum width of the printer, and stuff like that. I also did nt understand if the Hexadecimal data you send to the printer is actual ASCII - i.e. You send a real "F" character to get four dots "1111", or if you send a 15 decimal value standing for 0x0F ANd please, do confirm that you have PIL installed (call a interactive Python shell and type 'import Image' there if you are not sure). Regards, JS -><- On Friday 17 June 2005 01:22, Peter Dempsey wrote: > Hi folks, I'm a newbie to python so please be gentle. > > I want to convert an image to a format suitable for use in a Zebra > label printer. The data sent to the printer consists of a string of > hex characters. Each byte converts to a binary set of dots on the > label. > > FF becomes 11111111 > A5 becomes 10100101 > > So a string like this becomes a right-angle triangle... > > 18,3^m > F00000FF0000FFF000FFFF00FFFFF0FFFFFF > > The 18 says how many bytes in the image, 3 says how many bytes wide > the image is. So the string above becomes... > > F00000 -> 111100000000000000000000 > FF0000 -> 111111110000000000000000 > FFF000 -> 111111111111000000000000 > FFFF00 -> 111111111111111100000000 > FFFFF0 -> 111111111111111111110000 > FFFFFF -> 111111111111111111111111 > > I'm sure it's a simple task, I mean, the image is converted to a > hex representation of the raw image. > > I've had some success doing it the hard way with python, importing > a pcx image and going through it byte by byte but I'm sure there's > an easier way. > > Any suggestions would be super. > > I don't have my code here at home. I can post it tomorrow if it > helps. > > Thanks, > > Peter > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig From fredrik at pythonware.com Sat Jun 18 11:30:40 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 18 Jun 2005 11:30:40 +0200 Subject: [Image-SIG] Converting to zebra (ZPL) format References: <200506170522.10137.yarglags@eircom.net> <200506172240.47031.gwidion@mpc.com.br> Message-ID: Joao S. O. Bueno Calligaris wrote: > despite Fredik's lengthy and carefull answer, I think that is not what > you were asking for - his program is suitable to print images inpout > inline inside a Python program as sequences of 0 and 1's. the first section of the script was sample code which illustrated how to get from Peter's description to a mode "1" image. as the comments below the script implied, what PIL function you get the mode "1" image doesn't really matter (Image.open or Image.new+ImageDraw or ImageGrab or...) From yarglags at eircom.net Sun Jun 19 03:31:15 2005 From: yarglags at eircom.net (Peter Dempsey) Date: Sun, 19 Jun 2005 02:31:15 +0100 Subject: [Image-SIG] Converting to zebra (ZPL) format In-Reply-To: <200506172240.47031.gwidion@mpc.com.br> References: <200506170522.10137.yarglags@eircom.net> <200506172240.47031.gwidion@mpc.com.br> Message-ID: <200506190231.15898.yarglags@eircom.net> On Saturday 18 Jun 2005 02:40, you wrote: > Hi Peter, > > despite Fredik's lengthy and carefull answer, I think that is not what > you were asking for - his program is suitable to print images inpout > inline inside a Python program as sequences of 0 and 1's. > > But I think you were asking for a way to print a generic image read > from a disk file. > > I can code that for you, if you wish so - just write me if no one else > mailed yu a complete answer, and tell me more details about the > images you want to print, maximum width of the printer, and stuff > like that. > > I also did nt understand if the Hexadecimal data you send to the > printer is actual ASCII - i.e. You send a real "F" character to get > four dots "1111", or if you send a 15 decimal value standing for 0x0F > > ANd please, do confirm that you have PIL installed (call a interactive > Python shell and type 'import Image' there if you are not sure). > > Regards, > JS > -><- Thanks for the reply folks. Here is the code I have produced so far... #! /usr/bin/python import sys import string def hexit(n): # convert n to two digit Hex string. result = string.upper(str(hex(ord(n))))[2:4] if len(result) == 1: result = '0' + result return result def ImageWidth(n): # read image width from PCX header n = 1 + (ord(n[8]) + ord(n[9]) * 256) - (ord(n[4]) + ord(n[5]) * 256) if n % 8 > 0: # if mod width non zero image needs extra byte n = n / 8 + 1 else: n = n / 8 return n def ImageHeight(n): # read height from PCX header return 1 + (ord(n[10]) + ord(n[11]) * 256) - (ord(n[6]) + ord(n[7]) * 256) def PrintDetails(n): print 'Input length:\t', len(n) print 'Image Width: \t', ImageWidth(n), ' bytes' print 'Image Width: \t', 1 + (ord(n[8]) + ord(n[9]) * 256) - (ord(n[4]) + ord(n[5]) * 256), ' px' print 'Image Height:\t', ImageHeight(n) print 'Bits/Pixel: \t', ord(n[3]), '\n' def hex2dec(n): # convert hex digit to decimal return string.find('0123456789ABCDEF',n) def invhex(n): # forgot that printer treats 1 as 'on' - no ink dot. n = string.upper(hex(255 - hex2dec(n[0])*16 - hex2dec(n[1]))[2:]) if len(n) == 2: return n else: return '0'+n i = sys.argv[1:] for arg in i: try: source = open(arg, 'rb') dest = arg dest = dest[:string.find(dest,'.')]+'.hex' print 'Input file:\t', i print 'Output file:\t', dest except IOError: print 'cannot open', arg else: b=source.read() source.close() PrintDetails(b) header = '~DG_ZEBRA,' + str(ImageWidth(b) * ImageHeight(b)) + ',' + str(ImageWidth(b)) + ',\n' n="" mult = 0 # pcx byte multiplier begins with a 'C' for x in b[128:]: # Skip pcx header byte = hexit(x) if byte[:1] == 'C' and mult == 0: mult = hex2dec(byte[1]) else: if mult == 0: n = n + invhex(byte) else: n = n + invhex(byte) * mult mult = 0 n = header + n[:(ImageWidth(b) * ImageHeight(b)*2)] print 'Output:\n', n f=file(dest,"w") f.write(n) f.close() This works for small simple graphics but goes pear-shaped as the image size grows. I thought I was making some headway but, being new to python and image manipulation, I am getting disheartened. It could be to do with my understanding of the PCX file format. I just thought I was re-inventing the wheel and was missing something basic. The data sent to the printer is an ascii representation of the data, "FFFF0000" etc. Surely any graphic image ends up on screen as a set od pixels either on or off? The data read by the PIL must exist in a format that can be converted to binary to hex to ascii characters. I have PIL installed. I can read in from a file. The code above is written to work on a pcx file which, thanks to PIL, I can get from almost any image. FYI the programming manual for these printers is available here. http://www.servopack.de/Files/HB/ZPLbasics.pdf The download grapgic details are on page 202/211. Thanks again for the replies, Peter From douglas at paradise.net.nz Sun Jun 19 10:37:01 2005 From: douglas at paradise.net.nz (Douglas Bagnall) Date: Sun, 19 Jun 2005 20:37:01 +1200 Subject: [Image-SIG] Converting to zebra (ZPL) format In-Reply-To: <200506190231.15898.yarglags@eircom.net> References: <200506170522.10137.yarglags@eircom.net> <200506172240.47031.gwidion@mpc.com.br> <200506190231.15898.yarglags@eircom.net> Message-ID: <42B52EAD.2070002@paradise.net.nz> hi Peter, > > Thanks for the reply folks. Here is the code I have produced so far... > #! /usr/bin/python > > import sys > import string Don't use the string module, use the string type methods: http://python.org/doc/2.3.5/lib/string-methods.html Read the next page too, about string formatting. You'll find your helper functions are reducible to one-liners: def hexit(n): return "%.2X" % ord(n) def hex2dec(n): return int(n, 16) def invhex(n): return "%.2X" % (255 - ord(n)) It is also inadvisable to use "+" to build up a long string -- better to use a list, then join it up with ''.join(). Also, your code mixes tabs and spaces, which only leads to trouble in the long run. It ought to be possible to make you text editor stick to one or the other. Nevertheless, the main problem seems to be that you are ignoring PIL and parsing the image files yourself. I would suggest something like this: import sys import Image for arg in sys.argv[1:]: im = Image.open(arg) #this is equivalent to step 1 of Fredrik's reply. Step 2 went like this: data = im.tostring("raw", "1;I") size = len(data) data = ["%02X" % ord(byte) for byte in data] print "%d,%d^m" % (size, (im.size[0]+7)/8) print "".join(data) try it. douglas From fredrik at pythonware.com Mon Jun 20 12:48:39 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 20 Jun 2005 12:48:39 +0200 Subject: [Image-SIG] ANN: AGG-based drawing for PIL Message-ID: the "aggdraw" module is a prerelease of a new drawing library for PIL, based on Maxim Shemanarev's antigrain (AGG) graphics library. This module implements a WCK-style drawing interface (see below), and provides anti-aliasing and alpha compositing. downloads (windows only, at the moment. source will follow shortly): http://effbot.org/downloads/#aggdraw documentation: http://effbot.org/zone/pythondoc-aggdraw.htm (api reference) http://effbot.org/zone/draw-agg.htm (overview, slighty outdated) enjoy /F From janssen at parc.com Tue Jun 21 00:20:46 2005 From: janssen at parc.com (Bill Janssen) Date: Mon, 20 Jun 2005 15:20:46 PDT Subject: [Image-SIG] pil ten year anniversary In-Reply-To: Your message of "Wed, 15 Jun 2005 06:43:04 PDT." Message-ID: <05Jun20.152050pdt."58617"@synergy1.parc.xerox.com> Congrats! In case you didn't know, PIL is heavily used in UpLib (see http://www.parc.com/janssen/pubs/TR-03-16.pdf and http://www.parc.com/janssen/pubs/TR-04-11.pdf). Great work, Fredrik! Bill From yarglags at eircom.net Tue Jun 21 01:07:49 2005 From: yarglags at eircom.net (Peter Dempsey) Date: Tue, 21 Jun 2005 00:07:49 +0100 Subject: [Image-SIG] Converting to zebra (ZPL) format In-Reply-To: <42B52EAD.2070002@paradise.net.nz> References: <200506170522.10137.yarglags@eircom.net> <200506190231.15898.yarglags@eircom.net> <42B52EAD.2070002@paradise.net.nz> Message-ID: <200506210007.49307.yarglags@eircom.net> Thanks Douglas and Jaos for your replies. I made some progress today by using PIL today. I managed to load the image and cycle through the raw image data. The code is below. I'll look at your suggestion tomorrow, Douglas. The string types methods sound a bit more useful than my fumblings. As I said, I'm a newbie. About the spaces mixed with tabs, I'm using GVIM to edit the code but I'm one of those people who over-formats code. I like it to look orderly using whatever means comes to hand. My code produces a string of 1s and zeros corresponding to the image. I'll work out a way of converting it to ascii-hex tomorrow. The old code was an attempt to de-compress pcx data but I don't need to do that if I use PIL. If I convert the image to mono I should be able to use any source image. Ideally, I should be able to produce a decoder plug-in for ZPL but I have a lot to learn before that happens. Given the lack of hits I got while looking for a ready-made converter, there is not much demand for such a plug-in. Ah well, if it get it working I'll make it available and then work on others for DPL, Datamax Programming Language and BPL, Brady Programming Language. I may need one for Citizen ticket printers also. I'll stop rambling, here's my code. Thanks folks, Peter #! /usr/bin/env python import Image, sys, string def hexit(n): # convert n to two digit Hex string. result = string.upper(str(hex(ord(n))))[2:4] if len(result) == 1: result = '0' + result return result def ImageWidth(n): # read image width from PCX header if n % 8 > 0: # if mod width non zero image needs extra byte n = n / 8 + 1 else: n = n / 8 return n def ImageHeight(n): # read height from PCX header return 1 + (ord(n[10]) + ord(n[11]) * 256) - (ord(n[6]) + ord(n[7]) * 256) def PrintDetails(n): print 'Input length:\t', len(n) print 'Image Width: \t', ImageWidth(n), ' bytes' def hex2dec(n): # convert hex digit to decimal return string.find('0123456789ABCDEF',n) def invhex(n): # forgot that printer treats 1 as 'on' - no ink dot. n = string.upper(hex(255 - hex2dec(n[0])*16 - hex2dec(n[1]))[2:]) if len(n) == 2: return n else: return '0'+n i = sys.argv[1:] for arg in i: try: source = Image.open(arg) except IOError: print 'cannot open', arg else: dest = arg dest = dest[:string.find(dest,'.')]+'.hex' print 'Input file:\t\t', i[0] print 'Output file:\t\t', dest width=source.size[0] print 'Image Width (px):\t', width,' px' height=source.size[1] print 'Image Height (px):\t', height,' px' print 'Image Mode: \t\t', source.mode hexwidth=ImageWidth(width) print 'HexWidth:\t\t',hexwidth header = '~DG_ZEBRA,' + str(hexwidth*height) + ',' + str(hexwidth) + ',\n' print header n = '' for y in range(height): for x in range(width): pixel= source.getpixel((x,y)) if pixel==255: pixel=1 n=n+ str(pixel) print n del(source) #f=file(dest,"w") #f.write(n) #f.close() On Sunday 19 Jun 2005 09:37, Douglas Bagnall wrote: > hi Peter, > > > Thanks for the reply folks. Here is the code I have produced so far... > > #! /usr/bin/python > > > > import sys > > import string From gwidion at mpc.com.br Tue Jun 21 01:52:52 2005 From: gwidion at mpc.com.br (Joao S. O. Bueno Calligaris) Date: Mon, 20 Jun 2005 20:52:52 -0300 Subject: [Image-SIG] Converting to zebra (ZPL) format In-Reply-To: <200506210007.49307.yarglags@eircom.net> References: <200506170522.10137.yarglags@eircom.net> <42B52EAD.2070002@paradise.net.nz> <200506210007.49307.yarglags@eircom.net> Message-ID: <200506202052.52311.gwidion@mpc.com.br> On Monday 20 June 2005 20:07, Peter Dempsey wrote: > Thanks Douglas and Jaos for your replies. > Ideally, I should be able to produce a decoder plug-in for ZPL but > I have a lot to learn before that happens. Given the lack of hits I > got while looking for a ready-made converter, there is not much > demand for such a plug-in. Ah well, if it get it working I'll make > it available and then work on others for DPL, Datamax Programming > Language and BPL, Brady Programming Language. I may need one for > Citizen ticket printers also. > If you are diving into writing code for these pritners, you mguiht whant to get in touch with people at the Linux Printing project, so that yu code may become apropriate drivers for these devices in the end. Maybe they will further point you to either gutenprint (ex gimp-print) or Ghostscript devel. either way, it'd mean that these printers would be supported "out of the box" for millions of GNU/Linux (and other systems) worldwide. Regards, JS -><- From fredrik at pythonware.com Tue Jun 21 06:03:46 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 21 Jun 2005 06:03:46 +0200 Subject: [Image-SIG] Converting to zebra (ZPL) format References: <200506170522.10137.yarglags@eircom.net><200506190231.15898.yarglags@eircom.net><42B52EAD.2070002@paradise.net.nz> <200506210007.49307.yarglags@eircom.net> Message-ID: Peter Dempsey wrote: > I made some progress today by using PIL today. I managed to load the image and > cycle through the raw image data. The code is below. I'll look at your > suggestion tomorrow, Douglas. The string types methods sound a bit more > useful than my fumblings. so why not use the code I posted? unlike your code, it actually does what you said you wanted. > As I said, I'm a newbie. that's no excuse for rude behaviour. From fredrik at pythonware.com Tue Jun 21 11:04:35 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 21 Jun 2005 11:04:35 +0200 Subject: [Image-SIG] AGG-based drawing for PIL References: Message-ID: > downloads (windows only, at the moment. source will follow shortly): > > http://effbot.org/downloads/#aggdraw a self-contained source kit is now available. if you want text support, you need freetype2, and you also need to tweak the setup.py file a little. From yarglags at eircom.net Wed Jun 22 04:40:19 2005 From: yarglags at eircom.net (Peter Dempsey) Date: Wed, 22 Jun 2005 03:40:19 +0100 Subject: [Image-SIG] Converting to zebra (ZPL) format In-Reply-To: <42B52EAD.2070002@paradise.net.nz> References: <200506170522.10137.yarglags@eircom.net> <200506190231.15898.yarglags@eircom.net> <42B52EAD.2070002@paradise.net.nz> Message-ID: <200506220340.19324.yarglags@eircom.net> Hi Douglas, Your solution worked very well with a couple of minor tweaks. 'Takes a lot less lines of code than my effort. This is what I came up with today... #! /usr/bin/env python import Image, sys for arg in sys.argv[1:]: im = Image.open(arg).convert("1").rotate(0) # convert("1") means can use # colour images data = im.tostring("raw", "1;I") size = len(data) data = ["%02X" % ord(byte) for byte in data] name = arg[:arg.rfind('.')][:8]+'.GRF' # name can be '8.3' defaults to '.GRF' print "~DG%s,%d,%d," % (name,size, (im.size[0]+7)/8) # no need for the '^m' print "".join(data) print "^FO 40, 40 ^IM%s ^FS" % (name) # Print graphic at 40,40 I rarely need to do more than one image at a time so I think I'll play around with arguments for rotation and scaling. I was making some progress with my previous version but Bog knows what my loops on the data would have turned into. ZPL image data can be compressed using the scheme described in the pdf manual. I might look into this once I figure out how this code works. I have used a '+' in my code. I have not got the hang of ''.join() yet. The three functions you described were much simpler than mine. I have a lot to learn. Thanks very much for you help, Peter On Sunday 19 Jun 2005 09:37, Douglas Bagnall wrote: > hi Peter, > > def hexit(n): > return "%.2X" % ord(n) > > def hex2dec(n): > return int(n, 16) > > def invhex(n): > return "%.2X" % (255 - ord(n)) > > import sys > import Image > > for arg in sys.argv[1:]: > im = Image.open(arg) > > #this is equivalent to step 1 of Fredrik's reply. Step 2 went like this: > > data = im.tostring("raw", "1;I") > size = len(data) > data = ["%02X" % ord(byte) for byte in data] > > print "%d,%d^m" % (size, (im.size[0]+7)/8) > print "".join(data) > > try it. > > douglas From fredrik at pythonware.com Wed Jun 22 10:37:49 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 22 Jun 2005 10:37:49 +0200 Subject: [Image-SIG] Converting to zebra (ZPL) format References: <200506170522.10137.yarglags@eircom.net><200506190231.15898.yarglags@eircom.net><42B52EAD.2070002@paradise.net.nz> <200506220340.19324.yarglags@eircom.net> Message-ID: Peter Dempsey wrote: > Hi Douglas, > > Your solution worked very well with a couple of minor tweaks. wow. it's things like this that makes you wonder why you spend time helping people. From fredrik at pythonware.com Wed Jun 22 14:57:44 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 22 Jun 2005 14:57:44 +0200 Subject: [Image-SIG] Converting CMYK JPG image to RGB References: <42B2C996.9020604@u-prod.com> Message-ID: marc birot wrote: > I'm trying to convert CMYK Jpg files to RGB Jpg files using > (Image.open("cmyk_image.jpg").convert("RGB"))... > The result shows very wrong colours. > > After checking the Image-SIG archives (Aug 2004) i found the following : > > "...Older versions of Photoshop generated broken CMYK files, and PIL > attempts to compensate for this. try commenting out the following lines > in PIL/JpegImagePlugin.py, and let me know if it helps: > if self.mode == "CMYK" and self.info.has_key("adobe"): > rawmode = "CMYK;I" # Photoshop 2.5 is broken! ..." > > Well, i tried and it does not work. The result i get is close to a > 'negative' of the original picture ( not too close). PIL's CMYK conversion isn't very exact, and can be far from the result you get from proper pre-print stuff. if the negative is about as wrong as the "positive", using a better conversion library is your best bet (see Kevin's reply for more info) From web at contrastsweb.com Thu Jun 23 21:54:58 2005 From: web at contrastsweb.com (Rob Ballou) Date: Thu, 23 Jun 2005 14:54:58 -0500 Subject: [Image-SIG] Opening and saving quality JPEG files Message-ID: <1f43ce9f925a6aa68755570b829f7dc2@contrastsweb.com> Hello, I'm new to using PIL and I have what I hope is a quick question. I have created a script for displaying images to a web browser and I have noticed that the quality PIL saves JPEGs isn't entirely what I'm after. When displaying thumbnails (the main use of the script), the quality is great. But when displaying a full size image without modification, I noticed that there is some new JPEG compression taking place (there are pronounced JPEG compression artifacts). The code that I have is: im = Image.open(file) print "Content-type: image/%s\r\n" % im.format.lower() out= cStringIO.StringIO() im.save(out, format, quailty=100, optimize=1) out.reset() print out.read() out.close() Changing quality and the optimized attributes have little to no effect on the visual appearance of the image. I've tried to read the file directly in binary mode and print that back to the browser, but it can not display the image. I'm not really sure if I am going about these changes in the best manner. Thanks in advance for any help. Rob From chris at cogdon.org Thu Jun 23 22:09:19 2005 From: chris at cogdon.org (Chris Cogdon) Date: Thu, 23 Jun 2005 13:09:19 -0700 Subject: [Image-SIG] Opening and saving quality JPEG files In-Reply-To: <1f43ce9f925a6aa68755570b829f7dc2@contrastsweb.com> References: <1f43ce9f925a6aa68755570b829f7dc2@contrastsweb.com> Message-ID: <9f90f5a34895ec974a64fb0e3eee162c@cogdon.org> On Jun 23, 2005, at 12:54, Rob Ballou wrote: > Hello, > > I'm new to using PIL and I have what I hope is a quick question. > > I have created a script for displaying images to a web browser and I > have noticed that the quality PIL saves JPEGs isn't entirely what I'm > after. When displaying thumbnails (the main use of the script), the > quality is great. But when displaying a full size image without > modification, I noticed that there is some new JPEG compression taking > place (there are pronounced JPEG compression artifacts). > > The code that I have is: > > > im = Image.open(file) > print "Content-type: image/%s\r\n" % im.format.lower() > out= cStringIO.StringIO() > im.save(out, format, quailty=100, optimize=1) > out.reset() > print out.read() > out.close() > > > Changing quality and the optimized attributes have little to no effect > on the visual appearance of the image. I've tried to read the file > directly in binary mode and print that back to the browser, but it can > not display the image. > > I'm not really sure if I am going about these changes in the best > manner. Thanks in advance for any help. If you're not interested in processing the image, then there's no reason to run it through PIL Try this: im = Image.open(file) print "Content-type: image/%s\n" % im.format.lower() sys.stdout.write ( open(file).read() ) Ie... open it once so that PIL can get the format, then open it again to send through the web server. I'm using 'write' to avoid the extra newline at the end of the data (which is a bad thing to do). I'm also sending only a \n... the web server will automatically turn all newlines (\n) into NVT-ASCII newlines (\r\n). You don't want an extra \r in there. -- ("`-/")_.-'"``-._ Chris Cogdon . . `; -._ )-;-,_`) (v_,)' _ )`-.\ ``-' _.- _..-_/ / ((.' ((,.-' ((,/ fL From christianj at implicitnetworks.com Thu Jun 23 22:34:54 2005 From: christianj at implicitnetworks.com (Christian M. Jensen) Date: Thu, 23 Jun 2005 13:34:54 -0700 Subject: [Image-SIG] Opening and saving quality JPEG files Message-ID: <326A1C8DE34E8E4189BE602CE79167840947B9@corporate.implicit.implicitnetworks.com> Pre-calculating the content length and informing the browser is a good thing too. Search Google for "Content-Length" header info. -----Original Message----- From: image-sig-bounces at python.org [mailto:image-sig-bounces at python.org] On Behalf Of Chris Cogdon Sent: Thursday, June 23, 2005 1:09 PM To: Rob Ballou Cc: image-sig at python.org Subject: Re: [Image-SIG] Opening and saving quality JPEG files On Jun 23, 2005, at 12:54, Rob Ballou wrote: > Hello, > > I'm new to using PIL and I have what I hope is a quick question. > > I have created a script for displaying images to a web browser and I > have noticed that the quality PIL saves JPEGs isn't entirely what I'm > after. When displaying thumbnails (the main use of the script), the > quality is great. But when displaying a full size image without > modification, I noticed that there is some new JPEG compression taking > place (there are pronounced JPEG compression artifacts). > > The code that I have is: > > > im = Image.open(file) > print "Content-type: image/%s\r\n" % im.format.lower() > out= cStringIO.StringIO() > im.save(out, format, quailty=100, optimize=1) > out.reset() > print out.read() > out.close() > > > Changing quality and the optimized attributes have little to no effect > on the visual appearance of the image. I've tried to read the file > directly in binary mode and print that back to the browser, but it can > not display the image. > > I'm not really sure if I am going about these changes in the best > manner. Thanks in advance for any help. If you're not interested in processing the image, then there's no reason to run it through PIL Try this: im = Image.open(file) print "Content-type: image/%s\n" % im.format.lower() sys.stdout.write ( open(file).read() ) Ie... open it once so that PIL can get the format, then open it again to send through the web server. I'm using 'write' to avoid the extra newline at the end of the data (which is a bad thing to do). I'm also sending only a \n... the web server will automatically turn all newlines (\n) into NVT-ASCII newlines (\r\n). You don't want an extra \r in there. -- ("`-/")_.-'"``-._ Chris Cogdon . . `; -._ )-;-,_`) (v_,)' _ )`-.\ ``-' _.- _..-_/ / ((.' ((,.-' ((,/ fL _______________________________________________ Image-SIG maillist - Image-SIG at python.org http://mail.python.org/mailman/listinfo/image-sig From christianj at implicitnetworks.com Thu Jun 23 22:43:27 2005 From: christianj at implicitnetworks.com (Christian M. Jensen) Date: Thu, 23 Jun 2005 13:43:27 -0700 Subject: [Image-SIG] Opening and saving quality JPEG files Message-ID: <326A1C8DE34E8E4189BE602CE79167840947BA@corporate.implicit.implicitnetworks.com> Actually, while I am thinking about it - make sure your script handles HTTP HEAD requests with a 304 if the content has not changed - that will tell the browser to use a cached version of the content instead of asking for the new version. http://diveintopython.org/http_web_services/http_features.html#d0e27689 I know this is on the receiving end, but it might help with building the server - if that is what you are doing: http://diveintopython.org/http_web_services/etags.html -----Original Message----- From: image-sig-bounces+christianj=implicitnetworks.com at python.org [mailto:image-sig-bounces+christianj=implicitnetworks.com at python.org] On Behalf Of Christian M. Jensen Sent: Thursday, June 23, 2005 1:35 PM To: Chris Cogdon; Rob Ballou Cc: image-sig at python.org Subject: Re: [Image-SIG] Opening and saving quality JPEG files Pre-calculating the content length and informing the browser is a good thing too. Search Google for "Content-Length" header info. -----Original Message----- From: image-sig-bounces at python.org [mailto:image-sig-bounces at python.org] On Behalf Of Chris Cogdon Sent: Thursday, June 23, 2005 1:09 PM To: Rob Ballou Cc: image-sig at python.org Subject: Re: [Image-SIG] Opening and saving quality JPEG files On Jun 23, 2005, at 12:54, Rob Ballou wrote: > Hello, > > I'm new to using PIL and I have what I hope is a quick question. > > I have created a script for displaying images to a web browser and I > have noticed that the quality PIL saves JPEGs isn't entirely what I'm > after. When displaying thumbnails (the main use of the script), the > quality is great. But when displaying a full size image without > modification, I noticed that there is some new JPEG compression taking > place (there are pronounced JPEG compression artifacts). > > The code that I have is: > > > im = Image.open(file) > print "Content-type: image/%s\r\n" % im.format.lower() > out= cStringIO.StringIO() > im.save(out, format, quailty=100, optimize=1) > out.reset() > print out.read() > out.close() > > > Changing quality and the optimized attributes have little to no effect > on the visual appearance of the image. I've tried to read the file > directly in binary mode and print that back to the browser, but it can > not display the image. > > I'm not really sure if I am going about these changes in the best > manner. Thanks in advance for any help. If you're not interested in processing the image, then there's no reason to run it through PIL Try this: im = Image.open(file) print "Content-type: image/%s\n" % im.format.lower() sys.stdout.write ( open(file).read() ) Ie... open it once so that PIL can get the format, then open it again to send through the web server. I'm using 'write' to avoid the extra newline at the end of the data (which is a bad thing to do). I'm also sending only a \n... the web server will automatically turn all newlines (\n) into NVT-ASCII newlines (\r\n). You don't want an extra \r in there. -- ("`-/")_.-'"``-._ Chris Cogdon . . `; -._ )-;-,_`) (v_,)' _ )`-.\ ``-' _.- _..-_/ / ((.' ((,.-' ((,/ fL _______________________________________________ Image-SIG maillist - Image-SIG at python.org http://mail.python.org/mailman/listinfo/image-sig _______________________________________________ Image-SIG maillist - Image-SIG at python.org http://mail.python.org/mailman/listinfo/image-sig From chris at cogdon.org Thu Jun 23 23:12:19 2005 From: chris at cogdon.org (Chris Cogdon) Date: Thu, 23 Jun 2005 14:12:19 -0700 Subject: [Image-SIG] Opening and saving quality JPEG files In-Reply-To: <326A1C8DE34E8E4189BE602CE79167840947BA@corporate.implicit.implicitnetworks.com> References: <326A1C8DE34E8E4189BE602CE79167840947BA@corporate.implicit.implicitnetworks.com> Message-ID: <237b820307b3e9768d082987ed249602@cogdon.org> On Jun 23, 2005, at 13:43, Christian M. Jensen wrote: > Actually, while I am thinking about it - make sure your script handles > HTTP HEAD requests with a 304 if the content has not changed - that > will > tell the browser to use a cached version of the content instead of > asking for the new version. > > http://diveintopython.org/http_web_services/http_features.html#d0e27689 > > I know this is on the receiving end, but it might help with building > the > server - if that is what you are doing: > > http://diveintopython.org/http_web_services/etags.html Yep... all of that is good. Christian... we expect you to have a fully functioning apache clone, written in python, by Friday... hop to it! :) -- ("`-/")_.-'"``-._ Chris Cogdon . . `; -._ )-;-,_`) (v_,)' _ )`-.\ ``-' _.- _..-_/ / ((.' ((,.-' ((,/ fL From christianj at implicitnetworks.com Fri Jun 24 02:02:15 2005 From: christianj at implicitnetworks.com (Christian M. Jensen) Date: Thu, 23 Jun 2005 17:02:15 -0700 Subject: [Image-SIG] Opening and saving quality JPEG files Message-ID: <326A1C8DE34E8E4189BE602CE79167840947EC@corporate.implicit.implicitnetworks.com> Am I correct in the assumption that the check is already in the mail? -- maybe I could rewrite the apache.conf files to be actual XML :) -----Original Message----- From: image-sig-bounces at python.org [mailto:image-sig-bounces at python.org] On Behalf Of Chris Cogdon Sent: Thursday, June 23, 2005 2:12 PM To: image-sig at python.org Subject: Re: [Image-SIG] Opening and saving quality JPEG files On Jun 23, 2005, at 13:43, Christian M. Jensen wrote: > Actually, while I am thinking about it - make sure your script handles > HTTP HEAD requests with a 304 if the content has not changed - that > will > tell the browser to use a cached version of the content instead of > asking for the new version. > > http://diveintopython.org/http_web_services/http_features.html#d0e27689 > > I know this is on the receiving end, but it might help with building > the > server - if that is what you are doing: > > http://diveintopython.org/http_web_services/etags.html Yep... all of that is good. Christian... we expect you to have a fully functioning apache clone, written in python, by Friday... hop to it! :) -- ("`-/")_.-'"``-._ Chris Cogdon . . `; -._ )-;-,_`) (v_,)' _ )`-.\ ``-' _.- _..-_/ / ((.' ((,.-' ((,/ fL _______________________________________________ Image-SIG maillist - Image-SIG at python.org http://mail.python.org/mailman/listinfo/image-sig From gmduncan at swiftdsl.com.au Sun Jun 26 03:50:07 2005 From: gmduncan at swiftdsl.com.au (gmduncan) Date: Sun, 26 Jun 2005 11:50:07 +1000 Subject: [Image-SIG] Ken Burns effect Message-ID: <42BE09CF.4010205@swiftdsl.com.au> I'm wanting to apply this effect to images on a slideshow CD I've made. I thought Javascript may be the go, but a Google didn't show anything. I'm wondering if anyone using PIL has implemented the effect, and if so would they have an example script ? TIA. - Gary From simonwittber at gmail.com Mon Jun 27 18:03:30 2005 From: simonwittber at gmail.com (Simon Wittber) Date: Tue, 28 Jun 2005 00:03:30 +0800 Subject: [Image-SIG] Texture Synthesis Message-ID: <4e4a11f8050627090363eb15d6@mail.gmail.com> I've been trying (somewhat unsuccessfully) to implement some texture synthesis routines for PIL. Most of my results have been rather poor. Has anyone else tried this sort of thing? Sw. From cspence at sarnoff.com Tue Jun 28 15:27:26 2005 From: cspence at sarnoff.com (CLAY SPENCE) Date: Tue, 28 Jun 2005 09:27:26 -0400 Subject: [Image-SIG] Texture Synthesis In-Reply-To: References: Message-ID: <42C1503E.9010401@sarnoff.com> If you are looking for algorithm suggestions, Portilla and Simoncelli (http://www.cns.nyu.edu/~lcv/texture/) have one that works quite well. I'm sure there are others, but that's the one I know of. Clay Simon Wittber wrote: >I've been trying (somewhat unsuccessfully) to implement some texture >synthesis routines for PIL. > >Most of my results have been rather poor. Has anyone else tried this >sort of thing? > >Sw. > > > From bob at glumol.com Wed Jun 29 14:05:16 2005 From: bob at glumol.com (bob@glumol.com) Date: Wed, 29 Jun 2005 14:05:16 +0200 (CEST) Subject: [Image-SIG] PIL / wxPython conflict Message-ID: <55631.82.241.88.62.1120046716.squirrel@www.glumol.com> Hello, I get an exception when I run these 3 lines in every projet that use wxPython. import Image img = Image.open('bitmaps/image.png') img = img.tostring() -> EXCEPTION ! The program raises an IOError exception on line 207 from ImageFile.py (in PIL). 205 if not self.map and e < 0: 206 error = ERRORS.get(e, "decoder error %d" % e) 207 raise IOError(error + " when reading image file") Does someone know where it may come from ? It's possible that it comes from wxPython too. Thanks From jepler at unpythonic.net Wed Jun 29 14:20:38 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Wed, 29 Jun 2005 07:20:38 -0500 Subject: [Image-SIG] PIL / wxPython conflict In-Reply-To: <55631.82.241.88.62.1120046716.squirrel@www.glumol.com> References: <55631.82.241.88.62.1120046716.squirrel@www.glumol.com> Message-ID: <20050629122035.GA9733@unpythonic.net> Are you sure that 'bitmaps/image.png' is not an invalid image file? I damaged a PNG file and got this result while trying to .tostring() it: >>> img = Image.open("broken.png") >>> img = img.tostring() Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.3/site-packages/PIL/Image.py", line 436, in tostring import tempfile File "/usr/lib/python2.3/site-packages/PIL/ImageFile.py", line 192, in load raise IOError("image file is truncated (%d bytes not processed)" % len(b)) IOError: unknown error when reading image file Image.open() does not fully load the image, it just looks at headers to find such information as the resolution of the image. The full image is loaded when .load() is called explicitly, or some other method is called that requires the image be loaded. Therefore, it is no surprise that a damaged image might open() but give an exception later the first time the image data is used. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.python.org/pipermail/image-sig/attachments/20050629/018112ca/attachment.pgp From tim at timake.com Mon Jun 27 23:31:56 2005 From: tim at timake.com (Tim Ake) Date: Mon, 27 Jun 2005 21:31:56 -0000 Subject: [Image-SIG] PIL 1.1.5 - Loss of resolution Message-ID: <0MKz5u-1Dn1Cq3ieD-00071J@mrelay.perfora.net> Hi, I am using PIL 1.1.5 with Python 2.4, and am seeing a loss of resolution when dealing with images. I open an image that is 200 dpi, do a rotate, and save the rotated image. What I'm seeing is that the rotated image is saved at the same size, but is at 100 dpi instead of 200 dpi. My code frament is as follows: # open the tif file image im = Image.open(strFile) # rotate the image 90 degrees CCW om = im.rotate(90) # save the image as a.tif om.save("a.tif", "TIFF") #save the rotated file I can't afford a loss of resolution - any thoughts on maintaining my original resolution? Thanks! Tim Ake 335 Old Hickory Rd. Woodstock, GA 30188 mailto:tim at timake.com http://www.timake.com (770) 928-2433 (phone) (404) 944-4890 (cell) soli deo gloria -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20050627/958dd50b/attachment.html