使用 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,标记图像文件格式,表示用于在符合此文件格式标准的各种设备上使用的光栅图像。它能够在多个颜色空间中描述双层、灰度、调色板颜色和全彩色图像数据。它支持有损和无损压缩方案,以便为使用该格式的应用程序在空间和时间之间进行选择。该格式是可扩展的,并且经过多次修改,允许包含无限量的私人或特殊用途信息。该格式不依赖于机器,并且不受处理器、操作系统或文件系统等限制。
阅读更多