使用 Python 进行 EMF 图像合并
创建 Python 应用程序以通过服务器 API 合并 EMF 图像和照片
如何使用 Python 合并 EMF 图像和照片
利用拼贴技术,您可以从一组预先存在的图像和照片中制作出迷人的作品。 Python 库提供了无缝合并图像和照片的功能,无论其源文件格式如何变化。突出您的作品集的有效策略是使用带有重复图像或图案的壁纸装饰,允许水平和垂直排列。如果您的目标是展示文件处理的结果,那么在应用图像效果之前和之后无缝合并两个图像是一项简单的任务。要合并 EMF 图像,我们将使用 Aspose.Imaging for Python via .NET API 是一个功能丰富、功能强大且易于使用的图像处理和转换 API,适用于 Python 平台。您可以使用系统命令中的以下命令安装它。
系统命令行
>> pip install aspose-imaging-python-net
通过 Python 合并 EMF 的步骤
您需要 aspose-imaging-python-net 在您自己的环境中尝试以下工作流程。
- 使用 Image.Load 方法加载 EMF 文件
- 将图像组合成新图像
- 以 Aspose.Imaging 支持的格式将合并后的图像保存到光盘
系统要求
所有主要操作系统都支持 Python 的 Aspose.Imaging。只需确保您具有以下先决条件。
- 带有 .NET Core 运行时的 Microsoft Windows / Linux。
- Python 和 PyPi 包管理器。
合并 EMF 图像 - Python
from aspose.imaging import RasterImage, Image | |
from aspose.imaging.fileformats.tiff import TiffImage, TiffFrame | |
from aspose.imaging.fileformats.tiff.enums import TiffExpectedFormat | |
from aspose.imaging.imageoptions import TiffOptions, PdfOptions, PngOptions | |
from aspose.pycore import as_of | |
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 | |
data_dir = templates_folder | |
images = {} | |
files = ["template.emf", "template.wmf"] | |
max_width = 0 | |
max_height = 0 | |
i = 0 | |
for file_name in files: | |
with Image.load(os.path.join(data_dir, file_name)) as image: | |
output_file_name = os.path.join(data_dir, f"{file_name}{i}.png") | |
i += 1 | |
image.save(output_file_name, PngOptions()) | |
raster_image = Image.load(output_file_name) | |
if raster_image.width > max_width: | |
max_width = raster_image.width | |
if raster_image.height > max_height: | |
max_height = raster_image.height | |
images[output_file_name] = raster_image | |
output_path1 = os.path.join(data_dir, "multiframe.tiff") | |
output_path2 = os.path.join(data_dir, "multipage.pdf") | |
frame1 = next(iter(images.values())) | |
with TiffImage(TiffFrame(as_of(frame1, RasterImage))) as tiff_image: | |
# for loop | |
for path, page in images.items(): | |
if page != frame1: | |
tiff_image.add_page(as_of(page, RasterImage)) | |
tiff_image.save(output_path1, TiffOptions(TiffExpectedFormat.TIFF_JPEG_RGB)) | |
tiff_image.save(output_path2, PdfOptions()) | |
for path, image in images.items(): | |
# to dispose the image we call __exit__() | |
with image as _: | |
pass | |
if delete_output: | |
os.remove(path) | |
if delete_output: | |
os.remove(output_path1) | |
os.remove(output_path2) |
关于 Python API 的 Aspose.Imaging
Aspose.Imaging API 是一种图像处理解决方案,用于在应用程序中创建、修改、绘制或转换图像(照片)。它提供:跨平台的图像处理,包括但不限于各种图像格式之间的转换(包括统一的多页或多帧图像处理)、绘图等修改、使用图形基元、转换(调整大小、裁剪、翻转和旋转) 、二值化、灰度、调整)、高级图像处理功能(过滤、抖动、遮罩、去偏斜)和内存优化策略。它是一个独立的库,不依赖任何软件进行图像操作。可以在项目中使用原生 API 轻松添加高性能图像转换功能。这些是 100% 私有的本地 API,图像在您的服务器上处理。通过在线应用合并 EMF
通过访问我们的 Live Demos 网站 合并 EMF 文档。 现场演示有以下好处
EMF 什么是 EMF 文件格式
增强型元文件格式 (EMF) 独立于设备存储图形图像。 EMF 的元文件由按时间顺序排列的可变长度记录组成,可以在任何输出设备上解析后呈现存储的图像。这些可变长度记录可以是封闭对象的定义、绘图命令和对准确渲染图像至关重要的图形属性。当设备使用自己的图形环境打开 EMF 图元文件时,无论打开设备平台如何,原始图像的比例、尺寸、颜色和其他图形属性都保持不变。
阅读更多其他支持的合并格式
使用 Python,可以轻松合并不同的格式,包括。