PIL 套件 (剩餘模組的自動文件)

此處提供尚未移植或撰寫文件的模組參考。

PIL 模組

exception PIL.UnidentifiedImageError[來源]

基底類別: OSError

如果無法開啟和識別圖像,則會在 PIL.Image.open() 中引發此錯誤。

如果 PNG 圖像引發此錯誤,則將 ImageFile.LOAD_TRUNCATED_IMAGES 設定為 true 後,或許仍然可以開啟圖像。此設定會忽略遺失的資料和檢查碼失敗。

BdfFontFile 模組

剖析 X Bitmap Distribution Format (BDF)

class PIL.BdfFontFile.BdfFontFile(fp: BinaryIO)[來源]

基底類別: FontFile

X11 BDF 格式的字型檔案外掛程式。

PIL.BdfFontFile.bdf_char(f: BinaryIO) tuple[str, int, tuple[tuple[int, int], tuple[int, int, int, int], tuple[int, int, int, int]], Image] | None[來源]

ContainerIO 模組

class PIL.ContainerIO.ContainerIO(file: IO, offset: int, length: int)[原始碼]

繼承自: IO

一個檔案物件,提供對現有檔案的一部分進行讀取存取的功能 (例如 TAR 檔案)。

close() None[原始碼]
fileno() int[原始碼]
flush() None[原始碼]
isatty() bool[原始碼]
read(n: int = -1) AnyStr[原始碼]

讀取資料。

參數:

n – 要讀取的位元組數。 如果省略、零或負數,則讀取到區域末端。

回傳:

一個 8 位元字串。

readable() bool[原始碼]
readline(n: int = -1) AnyStr[原始碼]

讀取一行文字。

參數:

n – 要讀取的位元組數。 如果省略、零或負數,則讀取到行尾。

回傳:

一個 8 位元字串。

readlines(n: int | None = -1) list[AnyStr][原始碼]

讀取多行文字。

參數:

n – 要讀取的行數。 如果省略、零、負數或 None,則讀取到區域末端。

回傳:

一個 8 位元字串列表。

seek(offset: int, mode: int = 0) int[原始碼]

移動檔案指標。

參數:
  • offset – 位元組偏移量。

  • mode – 起始位置。使用 0 表示區域的開頭、1 表示目前的偏移量,以及 2 表示區域的末端。 您不能將指標移動到定義區域之外。

回傳:

從區域開始的偏移量,以位元組為單位。

seekable() bool[原始碼]
tell() int[原始碼]

取得目前的檔案指標。

回傳:

從區域開始的偏移量,以位元組為單位。

truncate(size: int | None = None) int[原始碼]
writable() bool[原始碼]
write(b: AnyStr) NoReturn[原始碼]
writelines(lines: Iterable) NoReturn[原始碼]

FontFile 模組

class PIL.FontFile.FontFile[原始碼]

基底類別:object

點陣字型檔案處理程式的基底類別。

bitmap: Image | None = None
compile() None[原始碼]

建立度量和點陣圖

save(filename: str) None[原始碼]

儲存字型

PIL.FontFile.puti16(fp: BinaryIO, values: tuple[int, int, int, int, int, int, int, int, int, int]) None[原始碼]

寫入網路順序(大端)16 位元序列

GdImageFile 模組

注意

此格式無法自動辨識,因此該類別未註冊以與 PIL.Image.open() 一起使用。若要開啟 gd 檔案,請改用 PIL.GdImageFile.open() 函式。

警告

GD 格式並非設計用於資料交換。此實作僅為方便和示範之用。

class PIL.GdImageFile.GdImageFile(fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None)[原始碼]

基底類別:ImageFile

用於 GD 未壓縮格式的影像外掛程式。請注意,標準 PIL.Image.open() 函式不支援此格式。若要使用此外掛程式,您必須匯入 PIL.GdImageFile 模組並使用 PIL.GdImageFile.open() 函式。

format: str | None = 'GD'
format_description: str | None = 'GD 未壓縮影像'
PIL.GdImageFile.open(fp: StrOrBytesPath | IO[bytes], mode: str = 'r') GdImageFile[原始碼]

從 GD 影像檔載入紋理。

參數:
  • fp – GD 檔名或已開啟的檔案控制代碼。

  • mode – 選用模式。在此版本中,如果提供模式引數,則必須為「r」。

回傳:

一個影像實例。

引發:

OSError – 如果無法讀取影像。

GimpGradientFile 模組

將曲線線段轉換為調色盤數值的內容(衍生自 GIMP 中對應的程式碼,由 Federico Mena Quintero 編寫。如需更多資訊,請參閱 GIMP 發行版。)

PIL.GimpGradientFile.EPSILON = 1e-10
class PIL.GimpGradientFile.GimpGradientFile(fp: IO[bytes])[原始碼]

基底類別:GradientFile

GIMP 漸層格式的檔案處理程式。

class PIL.GimpGradientFile.GradientFile[原始碼]

基底類別:object

getpalette(entries: int = 256) tuple[bytes, str][原始碼]
gradient: list[tuple[float, float, float, list[float], list[float], Callable[[float, float], float]]] | None = None
PIL.GimpGradientFile.SEGMENTS = [<function linear>, <function curved>, <function sine>, <function sphere_increasing>, <function sphere_decreasing>]
PIL.GimpGradientFile.curved(middle: float, pos: float) float[原始碼]
PIL.GimpGradientFile.linear(middle: float, pos: float) float[原始碼]
PIL.GimpGradientFile.sine(middle: float, pos: float) float[原始碼]
PIL.GimpGradientFile.sphere_decreasing(middle: float, pos: float) float[原始碼]
PIL.GimpGradientFile.sphere_increasing(middle: float, pos: float) float[原始碼]

GimpPaletteFile 模組

class PIL.GimpPaletteFile.GimpPaletteFile(fp: IO[bytes])[原始碼]

基底類別:object

GIMP 調色盤格式的檔案處理器。

getpalette() tuple[bytes, str][原始碼]
rawmode = 'RGB'

ImageDraw2 模組

(實驗性) WCK 風格的繪圖介面操作

另請參閱

PIL.ImageDraw

類別 PIL.ImageDraw2.Pen(color: str, width: int = 1, opacity: int = 255)[原始碼]

基底類別:object

儲存外框顏色和寬度。

類別 PIL.ImageDraw2.Brush(color: str, opacity: int = 255)[原始碼]

基底類別:object

儲存填充顏色

類別 PIL.ImageDraw2.Font(color: str, file: StrOrBytesPath | BinaryIO, size: float = 12)[原始碼]

基底類別:object

儲存 TrueType 字型和顏色

類別 PIL.ImageDraw2.Draw(image: Image | str, size: tuple[int, int] | list[int] | None = None, color: float | tuple[float, ...] | str | None = None)[原始碼]

基底類別:object

(實驗性) WCK 風格繪圖介面

flush() Image[原始碼]
render(op: str, xy: Sequence[float] | Sequence[Sequence[float]], pen: Pen | Brush | None, brush: Brush | Pen | None = None, **kwargs: Any) None[原始碼]
settransform(offset: tuple[float, float]) None[原始碼]

設定轉換偏移。

arc(xy: Sequence[float] | Sequence[Sequence[float]], pen: Pen | Brush | None, start: float, end: float, *options: Any) None[原始碼]

在給定的邊界框內,繪製起點和終點角度之間的弧線(圓形輪廓的一部分)。

chord(xy: Sequence[float] | Sequence[Sequence[float]], pen: Pen | Brush | None, start: float, end: float, *options: Any) None[原始碼]

arc() 相同,但會用直線連接端點。

ellipse(xy: Sequence[float] | Sequence[Sequence[float]], pen: Pen | Brush | None, *options: Any) None[原始碼]

在給定的邊界框內繪製橢圓。

line(xy: Sequence[float] | Sequence[Sequence[float]], pen: Pen | Brush | None, *options: Any) None[原始碼]

xy 清單中的座標之間繪製一條線。

pieslice(xy: Sequence[float] | Sequence[Sequence[float]], pen: Pen | Brush | None, start: float, end: float, *options: Any) None[原始碼]

與 arc 相同,但也會在邊界框的端點與中心之間繪製直線。

polygon(xy: Sequence[float] | Sequence[Sequence[float]], pen: Pen | Brush | None, *options: Any) None[原始碼]

繪製多邊形。

多邊形輪廓由給定座標之間的直線組成,加上最後一個和第一個座標之間的直線。

rectangle(xy: Sequence[float] | Sequence[Sequence[float]], pen: Pen | Brush | None, *options: Any) None[原始碼]

繪製矩形。

text(xy: tuple[float, float], text: AnyStr, font: Font) None[原始碼]

在給定位置繪製字串。

textbbox(xy: tuple[float, float], text: AnyStr, font: Font) tuple[float, float, float, float][原始碼]

傳回給定文字的邊界框(以像素為單位)。

回傳:

(左, 上, 右, 下) 邊界框

textlength(text: AnyStr, font: Font) float[原始碼]

傳回給定文字的長度(以像素為單位)。這是後續文字應該偏移的量。

ImageMode 模組

class PIL.ImageMode.ModeDescriptor(mode: str, bands: tuple[str, ...], basemode: str, basetype: str, typestr: str)[原始碼]

基礎類別:NamedTuple

模式字串的包裝器。

bands: tuple[str, ...]

欄位編號 1 的別名

basemode: str

欄位編號 2 的別名

basetype: str

欄位編號 3 的別名

mode: str

欄位編號 0 的別名

typestr: str

欄位編號 4 的別名

PIL.ImageMode.getmode(mode: str) ModeDescriptor[原始碼]

取得給定模式的模式描述器。

PaletteFile 模組

class PIL.PaletteFile.PaletteFile(fp: IO[bytes])[原始碼]

基底類別:object

Teragon 樣式調色盤檔案的檔案處理器。

getpalette() tuple[bytes, str][原始碼]
rawmode = 'RGB'

PcfFontFile 模組

class PIL.PcfFontFile.PcfFontFile(fp: BinaryIO, charset_encoding: str = 'iso8859-1')[原始碼]

基底類別: FontFile

用於 X11 PCF 格式的字型檔案外掛程式。

name = 'name'
PIL.PcfFontFile.sz(s: bytes, o: int) bytes[原始碼]

PngImagePlugin.iTXt 類別

class PIL.PngImagePlugin.iTXt(text: str, lang: str | None = None, tkey: str | None = None)[原始碼]

基礎類別:str

字串的子類別,允許 iTXt 區塊看起來像字串,同時保留其額外資訊

__new__(cls, text, lang, tkey)[原始碼]
參數:
  • value – 此鍵的值

  • lang – 語言代碼

  • tkey – 鍵名稱的 UTF-8 版本

lang: str | bytes | None
tkey: str | bytes | None

PngImagePlugin.PngInfo 類別

class PIL.PngImagePlugin.PngInfo[原始碼]

基底類別:object

PNG 區塊容器 (用於 save(pnginfo=))

add(cid: bytes, data: bytes, after_idat: bool = False) None[原始碼]

附加任意區塊。請謹慎使用。

參數:
  • cid – 一個位元組字串,長度為 4 個位元組。

  • data – 編碼資料的位元組字串

  • after_idat – 用於私有區塊。是否應在 IDAT 之後寫入區塊

add_itxt(key: str | bytes, value: str | bytes, lang: str | bytes = '', tkey: str | bytes = '', zip: bool = False) None[原始碼]

附加 iTXt 區塊。

參數:
  • key – 可用 latin-1 編碼的文字鍵名稱

  • value – 此鍵的值

  • lang – 語言代碼

  • tkey – 鍵名稱的 UTF-8 版本

  • zip – 壓縮旗標

add_text(key: str | bytes, value: str | bytes | iTXt, zip: bool = False) None[原始碼]

附加文字區塊。

參數:
  • key – 可用 latin-1 編碼的文字鍵名稱

  • value – 此鍵的值,文字或 PIL.PngImagePlugin.iTXt 實例

  • zip – 壓縮旗標

TarIO 模組

class PIL.TarIO.TarIO(tarfile: str, file: str)[原始碼]

基底類別:ContainerIO[bytes]

一個檔案物件,提供對 TAR 檔案中給定成員的讀取權限。

WalImageFile 模組

此讀取器基於以下規格: https://www.flipcode.com/archives/Quake_2_BSP_File_Format.shtml,並已使用 google 找到的一些範例檔案進行測試。

注意

此格式無法自動辨識,因此讀取器未註冊以用於 PIL.Image.open()。若要開啟 WAL 檔案,請改用 PIL.WalImageFile.open() 函式。

class PIL.WalImageFile.WalImageFile(fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None)[原始碼]

基底類別:ImageFile

format: str | None = 'WAL'
format_description: str | None = 'Quake2 Texture'
load() Image.core.PixelAccess | None[原始碼]

根據圖塊列表載入影像資料

PIL.WalImageFile.open(filename: StrOrBytesPath | IO[bytes]) WalImageFile[原始碼]

從 Quake2 WAL 紋理檔案載入紋理。

預設情況下,Quake2 標準調色盤會附加到紋理。若要覆寫調色盤,請使用 PIL.Image.Image.putpalette() 方法。

參數:

filename – WAL 檔案名稱或已開啟的檔案控制代碼。

回傳:

一個影像實例。