
- 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 - 建立水印
什麼是水印?
水印是指疊加在另一張影像、文件或物件上的可識別且通常是透明的影像或文字,用於指示所有權、作者身份或來源。水印通常用於保護智慧財產權和內容,防止未經授權的使用或分發,並提供歸屬資訊。它們服務於以下提到的各種目的:
版權保護 - 藝術家、攝影師和內容創作者經常使用水印來保護他們的智慧財產權,透過在其作品上標記他們的姓名、徽標或版權資訊。這有助於阻止未經授權使用或分發他們的內容。
品牌推廣 - 公司和組織使用水印在其影像或文件上打上他們的徽標、名稱或口號。這增強了他們的品牌標識,並明確了內容的來源。
文件驗證 - 水印可用於官方檔案(如證書)以防止偽造或未經授權的複製。例如,文憑或公證檔案可能帶有水印。
安全 - 在貨幣和其他安全文件中,複雜的且通常是不可見的。水印用於防止偽造。這些水印難以準確複製,從而更容易檢測到假鈔或偽造檔案。
影像歸屬 - 在版權圖片和影像許可的背景下,水印可用於顯示帶有水印的影像預覽。當用戶購買影像時,他們會收到沒有水印的版本。
數字媒體 - 在數字世界中,水印通常用於線上共享的影像和影片以保護內容。它們也可用於給予原始創作者榮譽。
水印可以採用各種形式,例如文字、徽標、圖案甚至嵌入到內容中的不可見資料。它們通常以難以去除的方式放置,而不會影響內容的質量,其目的是提供真實性或所有權的視覺或數字指示。
建立文字水印
現在讓我們探索如何使用 Pillow 庫建立文字水印。在 Pillow 中,沒有直接建立水印的方法,但我們可以使用ImageDraw、ImageFont和Image方法來實現。
以下是本章所有示例中使用的輸入影像。

示例
在這個示例中,我們使用 Pillow 庫建立了文字Tutorialspoint作為水印。
from PIL import Image, ImageDraw, ImageFont original_image = Image.open("Images/butterfly.jpg") draw = ImageDraw.Draw(original_image) watermark_text = "Tutorialspoint" font_size = 20 font = ImageFont.truetype("arial.ttf", font_size) text_color = (255, 255, 255) #White color (RGB) text_width, text_height = draw.textsize(watermark_text, font) image_width, image_height = original_image.size margin = 10 #Margin from the right and bottom edges position = (image_width - text_width - margin, image_height - text_height - margin) draw.text(position, watermark_text, font=font, fill=text_color) original_image.save("output Image/watermarked_image.png") original_image.show()
輸出

建立影像水印
之前我們在影像上建立了文字水印,同樣,我們可以使用 Pillow 中可用的ImageDraw、copy和paste方法建立影像作為水印。
示例
在這個示例中,我們使用 Pillow 中可用的方法建立了Tutoriaslpoint徽標影像作為水印。
from PIL import Image original_image = Image.open("Images/butterfly.jpg") watermark = Image.open("Images/tutorialspoint.png") #Use the appropriate image file for your watermark #Resize the watermark image to a specific width or height target_width = 200 #Adjust this to our preferred size aspect_ratio = float(target_width) / watermark.width target_height = int(watermark.height * aspect_ratio) watermark = watermark.resize((target_width, target_height), Image.ANTIALIAS) watermarked_image = original_image.copy() #Adjust the position where you want to place the watermark (e.g., bottom right corner) position = (original_image.width - watermark.width, original_image.height - watermark.height) watermarked_image.paste(watermark, position, watermark) watermarked_image.save("output Image/watermarked_image.jpg") watermarked_image.show()
輸出
