PMXBOT Log file Viewer

Help | Karma | Search:

#pil logs for Friday the 27th of December, 2013

(Back to #pil overview) (Back to channel listing) (Animate logs)
[21:04:23] <speckle> Hello, does anyone know how to specify a palette when converting an array of 8-bit image data from Numpy to Pillow using PIL.Image.fromarray? Documentation is unclear about this
[21:08:38] <wiredfool> I think you need to putpalette
[21:08:44] <wiredfool> after the fromarray call
[21:10:07] <speckle> thank you very much! sorry I did not find that myself
[21:10:24] <wiredfool> no problem
[21:10:59] <wiredfool> The documentation needs a going over, especially for things that aren't totally obvious from the code
[21:19:32] <speckle> I'm also unable to find the "TkImage" module to convert PIL images to Tk photos - I've tried various permutations but no luck
[21:19:50] <speckle> I'm unsure whether that's a tkinter module or a PIL module, though
[21:20:12] <wiredfool> I'm not really familiar with that part of the code
[21:20:35] <speckle> it seems like most of the tutorials are for Python 2, and the reorganization of the modules caused it to be buried somewhere for Python 3, and I have no idea where to look.. maybe I'll grep the source code, or maybe it's a separate package entirely. Hmm..
[21:21:16] <wiredfool> ah, look in Tk/tkImaging.c
[21:21:30] <speckle> Thanks!
[21:21:44] <speckle> I don't mind if you know a better way to display PIL images in a Tkinter GUI :)
[21:22:03] <wiredfool> umm, no. I went with wx
[21:22:31] <wiredfool> tk looked old when I looked at it ~8 years ago
[21:23:45] <wiredfool> I'm afraid you're deep into source reading to figure it out.
[21:24:14] <speckle> okay, I'll download the Tk and Pillow sources and start grepping them
[21:24:45] <speckle> Tk did get a makeover recently but I suppose it's still not as modern as wx
[21:24:58] <speckle> thanks for the tkImaging.c idea!
[21:25:12] <wiredfool> there's also _imageingtk.c
[21:25:21] <wiredfool> which is in the root directory
[21:39:31] <speckle> Maybe the bindings are missing :(
[21:40:54] <speckle> Either they are missing or Pillow is not installed properly on my system - even the import in the test script fails
[21:43:45] <speckle> Yeah, ImageTk.py is strangely missing from /usr/lib/python3/dist-packages/PIL/. Very odd
[21:49:05] <speckle> Okay, I got it by uninstalling my distro's package of Pillow, and reinstalling it from pip3. It seems very strange for distro package maintainers to silently leave out a file like that :(
[22:04:49] <wiredfool> I wonder if it's a split package
[22:06:55] <speckle> Could be - the version string says "python3-imaging 1.1.7+2.0.0-1ubuntu1"
[22:07:14] <wiredfool> deb or ubuntu?
[22:07:19] <speckle> Xubuntu 13.10
[22:08:08] <wiredfool> After our next release, I'm going to be pinging them to get 2.3 into the loops before 14.04LTS comes out.
[22:08:09] <speckle> Tried uninstalling and reinstalling it from the package manager, too
[22:08:15] <speckle> Nice!
[22:08:25] <wiredfool> the one they have is an old release
[22:09:23] <wiredfool> Thing is, on those two, if you're doing any dev, the pillow package compiles and installs so easily that it's almost not worth the maintainer's packages
[22:10:19] <speckle> Hmm, it looks like that ImageTk file existed since the 90s, though. Maybe it was a bug from an early edition of the version 2 branch, though, while you guys were in the middle of some transition or something
[22:11:12] <wiredfool> there's a lot of conditional compilation depending on libraries that are installed, so I'm guessing that it's a packaging/dependency thing.
[22:11:23] <speckle> Ah!
[22:11:44] <wiredfool> I'd guess that they wouldn't want to pull in all of tk for pillow, and yet, if they build against tk, it's going to be broken on machines where it's not installed
[22:11:52] <speckle> Well, it's more about keeping one's system consistent than ease of installation, since going half-and-half on Pypi and the package manager can cause some issues. Maybe I just need a separate change root for development packages, and then distribute all dependencies together with my software
[22:12:08] <wiredfool> so, they may want a python-pil-tk package, or something
[22:12:22] <speckle> Hmm, I thought Tk was automatically installed...
[22:12:41] <wiredfool> I don't think it's on my servers
[22:19:55] <speckle> Now "fromarray" it giving me the error message "Cannot handle this data type" - I wonder which data types it *can* handle :P I just passed it a 2d numpy array of integers ranging from 0 to 255
[22:22:39] <wiredfool> There are a set of numpy types, I think if you tag them uint8 it will work.
[22:22:47] <wiredfool> modes = [("L", 'uint8'),
[22:22:47] <wiredfool> ("I", 'int32'),
[22:22:47] <wiredfool> ("F", 'float32'),
[22:22:47] <wiredfool> ("RGB", 'uint8'),
[22:22:47] <wiredfool> ("RGBA", 'uint8'),
[22:22:48] <wiredfool> ("RGBX", 'uint8'),
[22:22:48] <wiredfool> ("CMYK", 'uint8'),
[22:22:49] <wiredfool> ("YCbCr", 'uint8'),
[22:22:49] <wiredfool> ("I;16", '<u2'),
[22:22:50] <wiredfool> ("I;16B", '>u2'),
[22:22:50] <wiredfool> ("I;16L", '<u2'),
[22:24:26] <speckle> Ah, I see - you have to manually set their type for Pillow to understand them. Thank you!
[22:26:53] <wiredfool> there are minimal examples in Tests/test_numpy.py
[22:33:33] <speckle> looks like there's another issue - _tkinter.TclError: invalid command name "PyImagingPhoto" inside ImageTk,py
[22:34:02] <speckle> could be the fact that I'm on Tk 8.5, while Pillow expects Tk 8.4
[22:34:59] <speckle> specifically, this line is giving the error: tk.call("PyImagingPhoto", self.__photo, block.id)
[22:35:34] <wiredfool> Hmm. we've been waying that it wworks with tk8.5
[22:35:37] <wiredfool> saying
[22:35:38] <wiredfool> works
[22:36:06] <wiredfool> ah. the test is minimal
[22:36:14] <wiredfool> import == success, fail == skip
[22:36:23] <wiredfool> test suite FTW!
[22:37:23] <speckle> I think I figured out the root cause of all these issues - I had the Tcl and Tk runtimes for 8.5 installed, but not the development libraries
[22:37:39] <speckle> somehow, that allowed Python to use it in a partially functional way
[22:38:04] <wiredfool> yeah, there's some wierdness there with tk
[22:38:16] <wiredfool> at least, I have a vague memory of it.
[22:39:27] <wiredfool> if you understand enough about tk to code up some basic tests I'd really appreciate getting them into the test suite
[22:39:29] <speckle> partially my fault for not installing the development libraries for everything I was using
[22:39:43] <wiredfool> then at least ther'd be examples and a known working state at one point in time
[22:40:09] <speckle> okay
[22:51:17] <speckle> Hooray, I can finally draw a shape in numpy and pass it to Tkinter through PIL :) It still doesn't work with Xubuntu's default Pillow installation, though - I still need to get it from pip3
[22:52:13] <speckle> I'm not sure how we'd write tests for GUIs, though - it's difficult to automate that without an advanced framework
[22:58:17] <wiredfool> well, if we make an image, pass that into a tkimage, then somehow check a few of the values
[22:58:31] <wiredfool> or if there are conversions both ways, we could try round tripping it.
[23:02:21] <speckle> Ah, yeah. We'd still have a lot to test without actually testing the visual GUI - either way, it would be an improvement