1. 产品
  2.   图片
  3.   Ruby
  4.   Aspose.Imaging Cloud SDK for Ruby

Aspose.Imaging Cloud SDK for Ruby

 
 

用于创建、调整大小、旋转和转换图像的 Ruby API

强大的基于云的图像处理 API,允许软件开发人员调整大小、裁剪、处理和转换各种图像格式。

Aspose.Imaging Cloud SDK for Ruby 是一个非常实用的基于云的图像处理 API,允许软件开发人员在 Ruby 应用程序内操作和转换多种图像文件格式。SDK 提供了一套全面的图像处理操作,包括调整大小、裁剪、旋转、翻转、过滤等等。SDK 提供了各种优化技术,可用于减小图像大小而不影响其质量。

Aspose.Imaging Cloud SDK for Ruby 提供了广泛的功能,允许软件开发人员在其应用程序内处理和转换图像,例如获取图像属性、调整图像大小并保存为其他格式、将图像转换为其他格式、将 TIFF 图像附加到其他格式、对图像进行倾斜校正、对图像应用过滤器、从多页图像中获取帧范围、反向图像搜索等等。此外,软件程序员可以使用 SDK 轻松地将图像从一种格式转换为另一种格式,例如 BMP、JPEG、PNG、GIF、TIFF、PSD 等。

Aspose.Imaging Cloud SDK for Ruby 已包含对多种图像格式的支持,例如 BMP、JPEG、PNG、GIF、JPEG2000、WEBP、PNG、WMF、EMF、SVG、TIFF、CMX、PSD 等。它是一种基于云的 API,可以从世界任何地方访问。开发人员无需在本地机器上安装任何软件即可使用该 API。如果您正在为 Ruby 应用程序寻找成像 API,Aspose.Imaging Cloud SDK for Ruby 绝对值得考虑。

Previous Next

开始使用 Aspose.Imaging Cloud SDK for Ruby

安装 Aspose.Imaging Cloud SDK for Ruby 的推荐方法是使用 RubyGems。请使用以下命令顺利安装。

通过 RubyGems 安装 Aspose.Imaging Cloud SDK for Ruby

gem build aspose-imaging-cloud.gemspec 
您也可以直接从Aspose 产品页面下载它。

通过 Ruby API 调整图像大小和裁剪

Aspose.Imaging Cloud SDK for Ruby 已提供对处理 Ruby 应用程序内图像调整大小和其他相关操作的完整支持。API 包括对裁剪图像、指定裁剪矩形的位置和尺寸、更改裁剪图像的格式、更新图像的宽度、修改图像的高度、调整现有图像的大小并将其保存为其他格式等的支持。以下示例演示了如何在 Ruby 应用程序内使用 SDK 调整图像大小。

如何使用 Ruby SDK 调整图像大小?

require 'aspose_imaging_cloud'
# Initialize the API client
imaging_api = AsposeImagingCloud::ImagingApi.new
# Set the image file name
name = 'image.png'
# Set the new size
new_width = 200
new_height = 200
# Call the resize_image API method
response = imaging_api.resize_image(name, new_width, new_height)
# Save the resized image
File.write('resized_image.png', response.content)

通过 Ruby 将图像转换为其他格式

Aspose.Imaging Cloud SDK for Ruby 已包含对多种图像格式的支持,例如 BMP、JPEG、PNG、GIF、TIFF、PSD 等。该 SDK 已包含对加载、查看和转换一些流行图像文件格式的支持,例如 BMP、GIF、DJVU、WMF、EMF、JPEG、JPEG2000、PSD、TIFF、WEBP、PNG、DICOM、CDR、CMX、ODG、DNG 和 SVG。软件开发人员还可以指定输入和输出图像名称、格式和其他参数,例如输入和输出文件夹。程序员可以轻松地将图像上传到云存储并将其转换为云中所需的图像格式。以下是示例代码,展示了软件开发人员如何使用 Ruby Cloud SDK 将图像转换为其他格式。

如何通过 Ruby API 将图像转换为其他格式?

require 'aspose_imaging_cloud'

# Configure Aspose.Imaging Cloud API credentials
config = AsposeImagingCloud::Configuration.new
config.client_id = 'Your App SID'
config.client_secret = 'Your App Key'

# Create an instance of the API client
imaging_api = AsposeImagingCloud::ImagingApi.new(config)

# Set the input image name and format
name = 'input.jpg'
format = 'png'

# Set the output image name and format
output_name = 'output.png'

# Convert the input image to the output format
imaging_api.convert_image(AsposeImagingCloud::ConvertImageRequest.new(name, format, output_format: output_format, folder: 'input_folder', out_path: 'output_folder/' + output_name))

puts 'Image converted successfully.'

通过 Ruby API 将滤镜应用于图像

Aspose.Imaging Cloud SDK for Ruby 使软件开发人员能够将滤镜应用于 Ruby 应用程序内的现有图像。该库包含几种重要的滤镜类型,例如 BigRectangular、SmallRectangular、Median、GaussWiener、MotionWiener、GaussianBlur、Sharpen、BilateralSmoothing 等。在以下示例中,GaussWiener 滤镜应用于半径为 2.0 且平滑度为 2.0 的图像。输出图像格式为 PNG,输出图像将保存到云存储中的“输出”文件夹中。

使用 Ruby SDK 将滤镜应用于图像

filter_type = 'GaussWiener'
filter_properties = {
    radius: 2.0,
    smooth: 2.0
}
output_format = 'png'

response = imaging_api.apply_filter(
    AsposeImagingCloud::ApplyFilterRequest.new(
        name: source_image,
        filter_type: filter_type,
        filter_properties: filter_properties,
        format: output_format,
        folder: 'output'
    )
)

// Download the output image:
output_image = 'output_image.png'

response = imaging_api.download_file(
    AsposeImagingCloud::DownloadFileRequest.new(
        path: "output/#{output_image}"
    )
)

File.open(output_image, 'wb') do |file|
    file.write(response)
end

 中国人