Get Details from an Image in Ruby
If you have a project or application that requires the editing and manipulation of images, it can be helpful to see exactly what you’re working with. In this quick tutorial, we will demonstrate how you can use an API in Ruby to extract details from an image, including color, transparency, MIME type, hash signature, and more.
First, we will add the Ruby client to your Gemfile:
gem 'cloudmersive-convert-api-client', '~> 2.1.6'
Once this is complete, we are ready to call the function by inputting the file into the following example code:
# load the gem
require 'cloudmersive-convert-api-client'
# setup authorization
CloudmersiveConvertApiClient.configure do |config|
# Configure API key authorization: Apikey
config.api_key['Apikey'] = 'YOUR API KEY'
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
#config.api_key_prefix['Apikey'] = 'Bearer'
endapi_instance = CloudmersiveConvertApiClient::ConvertImageApi.newinput_file = File.new('/path/to/inputfile') # File | Input file to perform the operation on.begin
#Get information about an image
result = api_instance.convert_image_get_image_info(input_file)
p result
rescue CloudmersiveConvertApiClient::ApiError => e
puts "Exception when calling ConvertImageApi->convert_image_get_image_info: #{e}"
end
After the request is submitted to the server, your response will be returned in just a few seconds. If you need to obtain an API key, visit the Cloudmersive website to register for a free account; this provides 800 calls/month across our library of APIs.