From f34d1f7db7dd4863f671cf6dd4fcf405adc67392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Veres-Szentkir=C3=A1lyi?= Date: Sat, 7 Dec 2013 10:49:43 +0100 Subject: [PATCH] added IronPython wrapper for PIL --- pysstv/__main__.py | 5 ++++- pysstv/monoPIL.py | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 pysstv/monoPIL.py diff --git a/pysstv/__main__.py b/pysstv/__main__.py index 0b8fc6a..7896897 100644 --- a/pysstv/__main__.py +++ b/pysstv/__main__.py @@ -1,7 +1,10 @@ #!/usr/bin/env python from __future__ import print_function -from PIL import Image +try: + from PIL import Image +except ImportError: + from monoPIL import Image from argparse import ArgumentParser from sys import stderr import color diff --git a/pysstv/monoPIL.py b/pysstv/monoPIL.py new file mode 100644 index 0000000..4261e77 --- /dev/null +++ b/pysstv/monoPIL.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python + +"""primitive partial PIL to IronPython (.Net) wrapper""" + +import clr +clr.AddReference("System.Drawing") +from System.Drawing import Image as SDI + +class Image(object): + @classmethod + def open(_cls, filename): + return Image(SDI.FromFile(filename)) + + def __init__(self, img): + self.img = img + self.size = (img.Width, img.Height) + + def convert(self, _ignore): + return self # TODO + + def load(self): + return self + + def __getitem__(self, (x, y)): + color = self.img.GetPixel(x, y) + return int(color.R), int(color.G), int(color.B)