我们从Python开源项目中,提取了以下31个代码示例,用于说明如何使用PIL.Image.getmodebase()。
def getcolor(color, mode): """ Same as :py:func:`~PIL.ImageColor.getrgb`, but converts the RGB value to a greyscale value if the mode is not color or a palette image. If the string cannot be parsed, this function raises a :py:exc:`ValueError` exception. .. versionadded:: 1.1.4 :param color: A color string :return: ``(graylevel [, alpha]) or (red, green, blue[, alpha])`` """ # same as getrgb, but converts the result to the given mode color, alpha = getrgb(color), 255 if len(color) == 4: color, alpha = color[0:3], color[3] if Image.getmodebase(mode) == "L": r, g, b = color color = (r*299 + g*587 + b*114)//1000 if mode[-1] == 'A': return (color, alpha) else: if mode[-1] == 'A': return color + (alpha,) return color
def show(self, image, **options): # save temporary image to disk if image.mode[:4] == "I;16": # @PIL88 @PIL101 # "I;16" isn't an 'official' mode, but we still want to # provide a simple way to show 16-bit images. base = "L" # FIXME: auto-contrast if max() > 255? else: base = Image.getmodebase(image.mode) if base != image.mode and image.mode != "1": image = image.convert(base) return self.show_image(image, **options) # hook methods
def show(self, image, **options): # save temporary image to disk if image.mode[:4] == "I;16": # @PIL88 @PIL101 # "I;16" isn't an 'official' mode, but we still want to # provide a simple way to show 16-bit images. base = "L" # FIXME: auto-contrast if max() > 255? else: base = Image.getmodebase(image.mode) if base != image.mode and image.mode != "1" and image.mode != "RGBA": image = image.convert(base) return self.show_image(image, **options) # hook methods
def __init__(self, image, size=None): if hasattr(image, "mode") and hasattr(image, "size"): mode = image.mode size = image.size else: mode = image image = None if mode not in ["1", "L", "P", "RGB"]: mode = Image.getmodebase(mode) self.image = Image.core.display(mode, size) self.mode = mode self.size = size if image: self.paste(image)
def __init__(self, image=None, size=None, **kw): # Tk compatibility: file or data if image is None: if "file" in kw: image = Image.open(kw["file"]) del kw["file"] elif "data" in kw: from io import BytesIO image = Image.open(BytesIO(kw["data"])) del kw["data"] if hasattr(image, "mode") and hasattr(image, "size"): # got an image instead of a mode mode = image.mode if mode == "P": # palette mapped data image.load() try: mode = image.palette.mode except AttributeError: mode = "RGB" # default size = image.size kw["width"], kw["height"] = size else: mode = image image = None if mode not in ["1", "L", "RGB", "RGBA"]: mode = Image.getmodebase(mode) self.__mode = mode self.__size = size self.__photo = tkinter.PhotoImage(**kw) self.tk = self.__photo.tk if image: self.paste(image)
def __init__(self, image=None, size=None, **kw): # Tk compatibility: file or data if image is None: image = _get_image_from_kw(kw) if hasattr(image, "mode") and hasattr(image, "size"): # got an image instead of a mode mode = image.mode if mode == "P": # palette mapped data image.load() try: mode = image.palette.mode except AttributeError: mode = "RGB" # default size = image.size kw["width"], kw["height"] = size else: mode = image image = None if mode not in ["1", "L", "RGB", "RGBA"]: mode = Image.getmodebase(mode) self.__mode = mode self.__size = size self.__photo = tkinter.PhotoImage(**kw) self.tk = self.__photo.tk if image: self.paste(image)