
- Python Pillow 教程
- Python Pillow - 首頁
- Python Pillow - 概述
- Python Pillow - 環境設定
- 基本影像操作
- Python Pillow - 處理影像
- Python Pillow - 調整影像大小
- Python Pillow - 翻轉和旋轉影像
- Python Pillow - 裁剪影像
- Python Pillow - 為影像新增邊框
- Python Pillow - 識別影像檔案
- Python Pillow - 合併影像
- Python Pillow - 剪下和貼上影像
- Python Pillow - 滾動影像
- Python Pillow - 在影像上寫入文字
- Python Pillow - ImageDraw 模組
- Python Pillow - 連線兩張影像
- Python Pillow - 建立縮圖
- Python Pillow - 建立水印
- Python Pillow - 影像序列
- Python Pillow 顏色轉換
- Python Pillow - 影像上的顏色
- Python Pillow - 使用顏色建立影像
- Python Pillow - 將顏色字串轉換為 RGB 顏色值
- Python Pillow - 將顏色字串轉換為灰度值
- Python Pillow - 透過更改畫素值來更改顏色
- 影像處理
- Python Pillow - 降噪
- Python Pillow - 更改影像模式
- Python Pillow - 影像合成
- Python Pillow - 使用 Alpha 通道
- Python Pillow - 應用透視變換
- 影像濾鏡
- Python Pillow - 為影像新增濾鏡
- Python Pillow - 卷積濾鏡
- Python Pillow - 模糊影像
- Python Pillow - 邊緣檢測
- Python Pillow - 浮雕影像
- Python Pillow - 增強邊緣
- Python Pillow - 銳化蒙版濾鏡
- 影像增強和校正
- Python Pillow - 增強對比度
- Python Pillow - 增強銳度
- Python Pillow - 增強色彩
- Python Pillow - 校正色彩平衡
- Python Pillow - 去噪
- 影像分析
- Python Pillow - 提取影像元資料
- Python Pillow - 識別顏色
- 高階主題
- Python Pillow - 建立動畫 GIF
- Python Pillow - 批次處理影像
- Python Pillow - 轉換影像檔案格式
- Python Pillow - 為影像新增填充
- Python Pillow - 顏色反轉
- Python Pillow - 使用 NumPy 進行機器學習
- Python Pillow 與 Tkinter BitmapImage 和 PhotoImage 物件
- Image 模組
- Python Pillow - 影像混合
- Python Pillow 有用資源
- Python Pillow - 快速指南
- Python Pillow - 函式參考
- Python Pillow - 有用資源
- Python Pillow - 討論
Python Pillow - ImageDraw.multiline_text() 函式
Pillow 庫中的 ImageDraw.multiline_text() 方法用於在影像上的指定位置繪製多行文字。
語法
以下是函式的語法:
ImageDraw.multiline_text(xy, text, fill=None, font=None, anchor=None, spacing=4, align='left', direction=None, features=None, language=None, stroke_width=0, stroke_fill=None, embedded_color=False, font_size=None)
引數
以下是此函式引數的詳細資訊:
xy - 文字的錨點座標。它指定錨點與文字對齊的位置。
text - 要繪製的字串,包含多行文字。
fill - 用於文字的顏色。
font - 一個 ImageFont 例項,表示用於文字的字型。
anchor - 文字錨點對齊方式。它確定錨點相對於文字的位置。預設對齊方式為左上角。
spacing - 行之間的畫素數。
align - 多行文字中行的對齊方式。可以是“left”(左對齊)、“center”(居中對齊)或“right”(右對齊)。
direction - 文字的方向。可以是“rtl”(從右到左)、“ltr”(從左到右)或“ttb”(從上到下)。
features - 在文字佈局期間要使用的 OpenType 字型功能列表。它用於啟用或停用可選字型功能。
language - 文字的語言。它應該是 BCP 47 語言程式碼。
stroke_width - 文字筆劃的寬度。
stroke_fill - 用於文字筆劃的顏色。如果未給出,則預設為 fill 引數。
embedded_color - 是否使用字型嵌入顏色字形 (COLR、CBDT、SBIX)。
font_size - 如果未提供 font 引數,則指定用於預設字型的尺寸。
示例
示例 1
在此示例中,multiline_text() 方法用於使用預設引數在影像上繪製多行文字。
from PIL import Image, ImageDraw, ImageFont # Create an image image = Image.new("RGB", (700, 300), "white") # Get a drawing context draw = ImageDraw.Draw(image) # Define the multiline text text = "Hello,\nThis is\nMultiline Text!" # Set the fill color for the text fill_color = 'green' # Draw multiline text on the image with default parameters draw.multiline_text((150, 130), text, fill=fill_color) # Display the image image.show() print('The multiline text is drawn successfully...')
輸出
The multiline text is drawn successfully...
輸出影像

示例 2
在此示例中,多行文字使用不同的引數繪製在影像上。
from PIL import Image, ImageDraw, ImageFont # Create a new image with a white background image = Image.new("RGB", (700, 300), "black") draw = ImageDraw.Draw(image) # Define the multiline text text = "Hello,\nThis is\nMultiline Text!" # Set the font and size font = ImageFont.truetype("arial.ttf", size=20) # Set fill color for the text fill_color = "orange" # Draw multiline text on the image draw.multiline_text((250, 100), text, fill=fill_color, font=font, spacing=10, align="left") # Display the image image.show() print('The multiline text is drawn successfully...')
輸出
The multiline text is drawn successfully...
輸出影像

示例 3
以下示例演示瞭如何在現有影像上使用不同的引數繪製多行文字。
from PIL import Image, ImageDraw, ImageFont # Open an Image image = Image.open('Images/TP-W.jpg') # Create the draw object draw = ImageDraw.Draw(image) # Define the multiline text multiline_text = "Tutorialspoint,\nSimple Easy Learning At Your Fingertips" # Set the font and size font = ImageFont.load_default() # Set fill color for the text fill_color = "darkgreen" # Draw multiline text on the image draw.multiline_text((240, 310), multiline_text, fill=fill_color, font=font, spacing=10, align="left") # Display the image image.show() print('Multiline text is drawn successfully...')
輸出
Multiline text is drawn successfully...

python_pillow_function_reference.htm
廣告