[IronPython] IronPython and PIL?
Markus Törnqvist
mjt at nysv.org
Fri Oct 23 16:10:10 CEST 2009
On Fri, Oct 23, 2009 at 02:42:23PM +0100, William Reade wrote:
> Hi Markus
>
> Parts of PIL should work with IronPython if you're willing to import
> ironclad first ( http://code.google.com/p/ironclad ). If you're still
> using ipy 2, the latest binary release should work for you.
I am not, because my primary objective is to get Django going, and
that depends on NWSGI, and the latest NWSGI is for the latest IPY :/
> (If you're using 2.6, it definitely won't work right now, because ipy
> 2.6 can't parse PIL.Image)
The code that I'm looking at is:
def get_image_dimensions(file_or_path):
"""Returns the (width, height) of an image, given an open file or a path."""
from PIL import ImageFile as PILImageFile
p = PILImageFile.Parser()
if hasattr(file_or_path, 'read'):
file = file_or_path
else:
file = open(file_or_path, 'rb')
while 1:
data = file.read(1024)
if not data:
break
p.feed(data)
if p.image:
return p.image.size
return None
That's very explicitly parsing, sorry :/
def get_image_dimensions(file_or_path):
img = System.Drawing.Image.FromFile(file_or_path)
size = (img.Size.Width, img.Size.Height)
return size
or somesuch may or may not fill the need here. I haven't tried
that code yet, I just coded it in this email ;P
> Incidentally, the reason I specify 'parts of' PIL is that it doesn't
> come with tests. I do have a few homebrew test cases that check for
> identical output when cpy and ipy do the same things -- and they do work
> -- but I can't claim any serious coverage.
>
> If you try Ironclad, please let me know how it works for you.
If the parsing doesn't work, I'm not sure there's much for me to try,
because I have a specific need here :|
Ironclad does, however, seem like a very good and much needed project
and if you get the 2.6 stuff going, it would be great! :)
Thanks!
--
mjt
More information about the Ironpython-users
mailing list