|
require 'fileutils'
|
|
require 'aspose-imaging-cloud'
|
|
|
|
IMAGE_FILE_NAME= 'example_image.jpeg2000';
|
|
IMAGES_FOLDER = 'ExampleImages';
|
|
CLOUD_FOLDER = 'CloudImages';
|
|
OUTPUT_FOLDER = 'Output';
|
|
|
|
# Get ClientId and ClientSecret from https://dashboard.aspose.cloud/
|
|
# or use on-premise version (https://docs.aspose.cloud/imaging/getting-started/how-to-run-docker-container/)
|
|
imaging_api = AsposeImagingCloud::ImagingApi.new(client_secret, client_id, 'https://api.aspose.cloud')
|
|
|
|
# Update an image from cloud storage
|
|
def update_image_from_storage
|
|
|
|
input_image = File.join(IMAGES_FOLDER, IMAGE_FILE_NAME)
|
|
upload_file_request = AsposeImagingCloud::UploadFileRequest.new(File.join(CLOUD_FOLDER, IMAGE_FILE_NAME), input_image)
|
|
result = self.imaging_api.upload_file(upload_file_request)
|
|
if result.errors.any?
|
|
puts('Uploading errors count: ' + result.errors.size.to_s)
|
|
|
|
# Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#update for possible formats
|
|
format = 'jpeg2000' # Resulting image format
|
|
new_width = 300
|
|
new_height = 450
|
|
x = 10
|
|
y = 10
|
|
rect_width = 200
|
|
rect_height = 300
|
|
rotate_flip_method = 'Rotate90FlipX' # RotateFlip method
|
|
folder = CLOUD_FOLDER # Input file is saved at the desired folder in the storage
|
|
storage = nil # We are using default Cloud Storage
|
|
|
|
request = AsposeImagingCloud::UpdateImageRequest.new(
|
|
IMAGE_FILE_NAME, new_width, new_height, x, y, rect_width, rect_height, rotate_flip_method, format, folder, storage)
|
|
updated_image = imaging_api.update_image(request)
|
|
|
|
# Save the image file to output folder
|
|
filename_part = File.basename(IMAGE_FILE_NAME, ".*")
|
|
image_name = filename_part + '.' + 'jpeg2000'
|
|
path = File.absolute_path(File.join(OUTPUT_FOLDER, image_name))
|
|
File.write(path, updated_image)
|
|
|
|
end
|
|
|
|
# Update an image. Image data is passed in a request stream
|
|
def create_updated_image_from_request
|
|
|
|
# Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#update for possible formats
|
|
format = 'jpeg2000' # Resulting image format
|
|
new_width = 300
|
|
new_height = 450
|
|
x = 10
|
|
y = 10
|
|
rect_width = 200
|
|
rect_height = 300
|
|
rotate_flip_method = 'Rotate90FlipX' # RotateFlip method
|
|
storage = nil # We are using default Cloud Storage
|
|
out_path = nil # Path to updated file (if this is empty, response contains streamed image)
|
|
input_stream = File.open(File.join(IMAGES_FOLDER, IMAGE_FILE_NAME), 'r')
|
|
|
|
request = AsposeImagingCloud::CreateUpdatedImageRequest.new(
|
|
input_stream, new_width, new_height, x, y, rect_width, rect_height, rotate_flip_method, format, out_path, storage)
|
|
updated_image = imaging_api.create_updated_image(request)
|
|
|
|
# Save the image file to output folder
|
|
filename_part = File.basename(IMAGE_FILE_NAME, ".*")
|
|
image_name = filename_part + '.' + 'jpeg2000'
|
|
path = File.absolute_path(File.join(OUTPUT_FOLDER, image_name))
|
|
File.write(path, updated_image)
|
|
|
|
end
|