使用 Python 作為 TIFF 影像浮水印
透過伺服器 API 建立為 TIFF 影像和照片添加浮水印的 Python 應用
如何使用 Python 為 TIFF 影像和照片添加浮水印
對於作者來說,加入浮水印是提高其品牌在網路空間中的知名度的絕佳方法。當應用於影像時,浮水印不僅可以作為來源或版權所有者的標識符,而且可以作為作者或線上平台的有效宣傳工具。這是因為浮水印,無論是作者的名字還是獨特的徽標,都會分散在圖像的每個數位迭代旁邊。水印選項包括圖像周圍各種字體的文字。半透明的標誌不會妨礙圖像或照片的視覺欣賞。如果作者或版權所有者認為強調他們的名字至關重要,水印可能會部分覆蓋圖像。要將浮水印加入 TIFF 影像中,我們將使用 Aspose.Imaging for Python via .NET API 是一個功能豐富、功能強大且易於使用的圖像處理和轉換 API,適用於 Python 平台。您可以使用系統命令中的以下命令安裝它。
系統命令行
>> pip install aspose-imaging-python-net
通過 Python 將水印添加到 TIFF 的步驟
您需要 aspose-imaging-python-net 在您自己的環境中嘗試以下工作流程。
- 使用 Image.Load 方法加載 TIFF 文件
- 從圖像創建圖形實例
- 定義水印文本的字體、畫筆和格式
- 使用 Graphics.DrawString 方法繪製水印
- 以 TIFF 格式將圖像保存到光盤
系統要求
所有主要操作系統都支持 Python 的 Aspose.Imaging。只需確保您具有以下先決條件。
- 帶有 .NET Core 運行時的 Microsoft Windows / Linux。
- Python 和 PyPi 包管理器。
水印 TIFF 圖像 - Python
import aspose.imaging as imaging | |
import aspose.pycore as aspycore | |
import os | |
if 'TEMPLATE_DIR' in os.environ: | |
templates_folder = os.environ['TEMPLATE_DIR'] | |
else: | |
templates_folder = r"C:\Users\USER\Downloads\templates" | |
delete_output = 'SAVE_OUTPUT' not in os.environ | |
# load an existing TIFF with Image.load | |
with imaging.Image.load(os.path.join(templates_folder, "template.tiff")) as image: | |
# create and initialize an instance of Graphics class and Initialize an object of SizeF to store image Size | |
graphics = imaging.Graphics(image) | |
size = graphics.image.size | |
# create an instance of Font. Initialize it with Font Face, Size and Style | |
font = imaging.Font("Times New Roman", 20.0, imaging.FontStyle.BOLD) | |
# create an instance of SolidBrush and set Color & Opacity | |
brush = imaging.brushes.SolidBrush() | |
brush.color = imaging.Color.red | |
brush.opacity = 0.0 | |
# initialize an object of StringFormat class and set its various properties | |
format_ = imaging.StringFormat() | |
format_.alignment = imaging.StringAlignment.CENTER | |
format_.format_flags = imaging.StringFormatFlags.MEASURE_TRAILING_SPACES | |
# draw the string on image | |
graphics.draw_string("CONFIDENTIAL", font, brush, image.width / 2, image.height / 2, format_) | |
# save output to disc | |
image.save(os.path.join(templates_folder, "output.tiff")) | |
if delete_output: | |
os.remove(os.path.join(templates_folder, "output.tiff")) |
關於 Python API 的 Aspose.Imaging
Aspose.Imaging API 是一種圖像處理解決方案,用於在應用程序中創建、修改、繪製或轉換圖像(照片)。它提供:跨平台的圖像處理,包括但不限於各種圖像格式之間的轉換(包括統一的多頁或多幀圖像處理)、繪圖等修改、使用圖形基元、轉換(調整大小、裁剪、翻轉和旋轉) 、二值化、灰度、調整)、高級圖像處理功能(過濾、抖動、遮罩、去偏斜)和內存優化策略。它是一個獨立的庫,不依賴任何軟件進行圖像操作。可以在項目中使用原生 API 輕鬆添加高性能圖像轉換功能。這些是 100% 私有的本地 API,圖像在您的服務器上處理。水印 TIFF 通過在線應用程序
訪問我們的 Live Demos 網站 ,為 TIFF 文檔添加水印。 現場演示有以下好處
TIFF 什麼是 TIFF 文件格式
TIFF 或 TIF,標記圖像文件格式,表示用於在符合此文件格式標準的各種設備上使用的光柵圖像。它能夠在多個顏色空間中描述雙層、灰度、調色板顏色和全彩色圖像數據。它支持有損和無損壓縮方案,以便為使用該格式的應用程序在空間和時間之間進行選擇。該格式是可擴展的,並且經過多次修改,允許包含無限量的私人或特殊用途信息。該格式不依賴於機器,並且不受處理器、操作系統或文件系統等限制。
閱讀更多