ImageShow 模組

ImageShow 模組用於顯示影像。所有預設檢視器都會將要顯示的影像轉換為 PNG 格式。

PIL.ImageShow.show(image: Image, title: str | None = None, **options: Any) bool[原始碼]

顯示給定的影像。

參數
  • image – 影像物件。

  • title – 選用標題。並非所有檢視器都能顯示標題。

  • **options – 其他檢視器選項。

傳回

如果找到合適的檢視器,則傳回 True,否則傳回 False

class PIL.ImageShow.IPythonViewer[原始碼]

IPython 前端的檢視器。

class PIL.ImageShow.WindowsViewer[原始碼]

Windows 上的預設檢視器是 PNG 檔案的預設系統應用程式。

class PIL.ImageShow.MacViewer[原始碼]

macOS 上使用 Preview.app 的預設檢視器。

class PIL.ImageShow.UnixViewer[原始碼]

如果找到給定的命令,則可以在基於 Unix 的系統上註冊以下檢視器

class XDGViewer

freedesktop.org xdg-open 命令。

class DisplayViewer

ImageMagick display 命令。此檢視器支援 title 參數。

class GmDisplayViewer

GraphicsMagick gm display 命令。

class EogViewer

GNOME 影像檢視器 eog 命令。

class XVViewer

X 檢視器 xv 命令。此檢視器支援 title 參數。

為了在基於 Unix 的系統上提供最大功能,Pillow 不會自動移除從影像建立的暫存檔。

PIL.ImageShow.register(viewer: type[Viewer] | Viewer, order: int = 1) None[原始碼]

register() 函式用於註冊其他檢視器

from PIL import ImageShow
ImageShow.register(MyViewer())  # MyViewer will be used as a last resort
ImageShow.register(MySecondViewer(), 0)  # MySecondViewer will be prioritised
ImageShow.register(ImageShow.XVViewer(), 0)  # XVViewer will be prioritised
參數
  • viewer – 要註冊的檢視器。

  • order – 零或負整數會將此檢視器附加到清單的前面,正整數會將其附加到清單的後面。

class PIL.ImageShow.Viewer[原始碼]

檢視器的基礎類別。

show(image: Image, **options: Any) int[原始碼]

用於顯示影像的主要函式。將給定的影像轉換為目標格式並顯示它。

format: str | None = None

要將影像轉換成的格式。

options: dict[str, Any] = {}

用於轉換影像的其他選項。

get_format(image: Image) str | None[原始碼]

傳回格式名稱,或 None 以另存為 PGM/PPM。

get_command(file: str, **options: Any) str[原始碼]

傳回用於顯示檔案的命令。基礎類別中未實作。

save_image(image: Image) str[原始碼]

儲存至暫存檔案並傳回檔名。

show_image(image: Image, **options: Any) int[原始碼]

顯示給定的影像。

show_file(path: str, **options: Any) int[原始碼]

顯示給定的檔案。