
Aspose.Imaging Cloud SDK for Python
Python REST API 用于创建和转换图像
用于图像处理的 Python REST SDK,使软件开发人员能够创建、编辑、压缩、操作、转换和压缩图像.
图像是现代通信的重要组成部分,可应用于社交媒体、广告、医疗保健等领域。高效准确地创建和处理图像是许多现代企业的关键要求。幸运的是,Aspose.Imaging Cloud SDK for Python 提供了处理图像的全面解决方案,使软件开发人员能够执行各种重要任务,例如创建、转换、调整大小、裁剪、查看、打印等等。Aspose.Imaging Cloud SDK for Python 的主要优势之一是它使软件开发人员无需任何专门的软件或硬件即可处理图像。
Aspose.Imaging Cloud SDK for Python 是一个基于云的 API,允许开发人员处理各种格式的各种类型的图像,例如 BMP、GIF、JPEG、JPEG2000、PSD、TIFF、WEBP、PNG、WMF、EMF、SVG 等等。该库还包含其他几个重要功能,例如从图像中提取元数据、颜色管理支持、处理图像中的多个图层、添加/删除或修改图层、向图像添加水印(文本和图像水印)、图像翻转和旋转、纠正图像方向问题、更改图像的视角等等
Aspose.Imaging Cloud SDK for Python 非常易于处理,允许开发人员轻松地将图像从一种格式转换为另一种格式,例如将 PNG 图像转换为 JPEG 或 BMP。该 SDK 支持多种图像格式,因此用途广泛。该 SDK 的另一个非常有用的功能是用户还可以使用 SDK 调整图像大小,这对于优化图像以用于特定目的(例如社交媒体帖子或网站设计)非常有用。该 SDK 支持比例和非比例调整大小。此外,它还允许用户裁剪图像以删除不需要的部分或专注于特定的感兴趣区域。用户可以指定裁剪参数,例如裁剪区域和裁剪模式。
开始使用 Aspose.Imaging Cloud SDK for Python
安装 Aspose.Imaging Cloud SDK for Python 的推荐方法是使用 PyPi。请使用以下命令顺利安装。
通过 PyPi 安装 Aspose.Imaging Cloud SDK for Python
pip install aspose-imaging-cloud
您也可以直接从Aspose 产品页面下载它。通过 Python API 在云中读取和写入图像
Aspose.Imaging Cloud SDK for Python 是一个非常有用的 REST API,它使计算机程序员能够执行各种图像处理操作,包括在云中创建、操作和转换,且无需任何初始成本。该库支持一些流行的图像文件格式,并允许读取和写入图像文件格式,如 BMP、GIF、JPEG、JPEG2000、PSD、TIFF、WEBP、PNG、WMF、EMF、SVG、TGA、APNG 等。创建图像后,软件开发人员可以根据自己的需求轻松加载和修改图像。以下示例演示了用户如何从云存储中读取图像。
如何通过 Python 从云存储读取/写入图像?
# set the input image path and format
name = 'input_image.jpg'
format = 'jpg'
folder = 'your_folder_path'
# send the request to the API to download the image
response = imaging_api.get_image_download(name, folder=folder, format=format)
# read the image data from the response
image_data = response.content
# Write an Image to the Cloud Storage via Python API
# set the output image path and format
name = 'output_image.jpg'
format = 'jpg'
folder = 'your_folder_path'
# send the request to the API to upload the image
response = imaging_api.create_updated_image(name, image_data, folder=folder, format=format)
# read the response to confirm the image was uploaded successfully
if response.status_code == 200:
print('Image uploaded successfully.')
else:
print('Error uploading image:', response.content)
通过 Python API 调整、裁剪和旋转图像
Aspose.Imaging Cloud SDK for Python 使软件开发人员能够在自己的云应用程序内执行各种图像处理操作。要完成调整大小任务,开发人员需要将图像上传到云存储,然后在 API URL 中传递其名称。更新图像参数后,API 会在响应中返回更新后的图像。REST API 还包含其他几个重要功能,例如旋转翻转图像、缩放图像、裁剪现有图像、将 TIFF 图像附加到另一幅图像等等。
如何通过 Python API 调整图像大小或裁剪图像?
import asposeimagingcloudsdk
from asposeimagingcloudsdk.models.requests import CreateResizedImageRequest, CreateCroppedImageRequest
# Initialize Aspose.Imaging Cloud API client
imaging_api = asposeimagingcloudsdk.ImagingApi(api_key='YOUR_API_KEY', app_sid='YOUR_APP_SID')
# Set the input image file name and format
filename = 'input_image.jpg'
format = 'jpg'
# Set the output image file name and format
output_filename = 'output_image.jpg'
output_format = 'jpg'
# Set the new size for the resized image
new_width = 500
new_height = 500
# Set the coordinates and size of the area to be cropped
x = 50
y = 50
width = 400
height = 400
# Create a request object for creating the resized image
resize_request = CreateResizedImageRequest(filename, new_width, new_height, format, output_format, folder='input')
# Call the API to resize the image and save the result to the cloud storage
response = imaging_api.create_resized_image(resize_request)
# Create a request object for creating the cropped image
crop_request = CreateCroppedImageRequest(output_filename, output_format, x, y, width, height, format, folder='output')
# Call the API to crop the image and save the result to the cloud storage
response = imaging_api.create_cropped_image(crop_request)
通过 Python API 使用 TIFF 帧
Aspose.Imaging Cloud SDK for Python 已包含对 Python 应用程序内的 TIFF(标记图像文件格式)图像的强大支持。该库有几个重要的功能部分用于处理 TIFF 文件格式,例如从多帧 TIFF 图像中提取帧、获取 TIFF 帧属性、调整 TIFF 帧大小、TIFF 帧旋转或翻转支持、裁剪 TIFF 帧、将 TIFF 帧附加到另一个 TIFF 图像、提取单个 TIFF 帧以供进一步处理等等。
云应用程序中的高级图像搜索
Aspose.Imaging Cloud SDK for Python 包含非常强大的支持,可在 Python 云应用程序中以不同方式搜索图像。该库允许软件开发人员执行反向图像搜索,这意味着源图像集包含至少一个与其他几个图像进行比较的图像。软件开发人员可以执行诸如比较两个图像、从搜索上下文中获取图像、在搜索上下文中更新图像特征、查找相似图像、查找重复图像、按标签搜索图像等操作。
如何通过 Python API 查找重复的图像?
# optional parameters are base URL, API version and debug mode
imaging_api = ImagingApi('yourClientSecret', 'yourClientId')
# create search context or use existing search context ID if search context was
# created earlier
api_response = imaging_api.create_image_search(CreateImageSearchRequest())
search_context_id = api_response.id
# extract images features if it was not done before
imaging_api.create_image_features(CreateImageFeaturesRequest(
search_context_id, image_id=None, images_folder='WorkFolder'))
# wait 'till image features extraction is completed
while imaging_api.get_image_search_status(
GetImageSearchStatusRequest(
search_context_id)).search_status != 'Idle':
time.sleep(10)
# request finding duplicates
response = imaging_api.find_image_duplicates(
FindImageDuplicatesRequest(search_context_id, 90))
# process duplicates search result
for duplicates in response.duplicates:
print('Duplicates:')
for duplicate in duplicates.duplicate_images:
print('ImageName: {0}, Similarity: {1}'.format(duplicate.image_id,
duplicate.similarity))