On Mon, Apr 13, 2009 at 5:01 AM, Guy K. Kloss <g.kl...@massey.ac.nz> wrote: > > Hi, > > I'm currently working on extending the ctypes based LCMS bindings, and I want > to support PIL image types natively inside the doTransform() method on a > Transform object. > > Anyway, for that task I need to distinguish between different valid object > types for the input buffer to decide which action to take. For NumPy arrays > that works nicely, but I don't know how to distinguish properly whether I'm > dealing with a PIL.Image type object. Below you can find some of the > tinkerings of the "obvious" candidates. > > So far it seems as if only the last one gives me a viable option, but it > doesn't strike me as being very pythonic, elegant or even clean in the code. > > Any suggestions? > > Guy > > > >>> type(a_numpy_array) > <type 'numpy.ndarray'> > >>> isinstance(a_numpy_array, numpy.ndarray) > True > >>> type(a_pil_image) > <type 'instance'> > >>> isinstance(a_pil_image, instance) > [...] > NameError: name 'instance' is not defined > >>> isinstance(inImage, PIL.Image) > [...] > TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and > types
>>> PIL.Image <module 'PIL.Image' from 'PIL\Image.pyc'> >>> PIL.Image.Image <class PIL.Image.Image at 0x00C5D720> >>> isinstance(inImage, PIL.Image.Image) True >>> PIL.Image.isImageType(inImage) True </F> _______________________________________________ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig