def to_image_type(image_type):
if image_type is None: return None<EOL>if isinstance(image_type, type) and issubclass(image_type, ImageType): return image_type<EOL>if pimms.is_str(image_type):<EOL><INDENT>image_type = image_type.lower()<EOL>if image_type in image_types_by_name: return image_types_by_name[image_type]<EOL>for it in image_types:<EOL><INDENT>if image_type in it.aliases(): return it<EOL><DEDENT>raise ValueError('<STR_LIT>' % image_type)<EOL><DEDENT>for x in (image_type, type(image_type)):<EOL><INDENT>try:    return image_types_by_image_type[x]<EOL>except Exception: pass<EOL>try:    return image_types_by_header_type[x]<EOL>except Exception: pass<EOL><DEDENT>raise ValueError('<STR_LIT>' % image_type)<EOL>
to_image_type(image_type) yields an image-type class equivalent to the given image_type
  argument, which may be a type name or alias or an image or header object or class.