class App42::ImageProcessor::ImageProcessorService

The ImageProcessor service is an Image utility service on the Cloud. Developers can upload files on the cloud and perform various Image Manipulation operations on the Uploaded Images e.g. resize, scale, thumbnail, crop etc. It is especially useful for Mobile Apps when they dont want to store Images locally and dont want to perform processor intensive operations. It is also useful for web applications who want to perform complex Image Operations

@see Image

Public Class Methods

new(api_key, secret_key, base_url) click to toggle source

this is a constructor that takes

@param apiKey @param secretKey @param baseURL

# File lib/imageProcessor/ImageProcessorService.rb, line 33
def initialize(api_key, secret_key, base_url)
  puts "Session Service->initialize"
  @api_key = api_key
  @secret_key = secret_key
  @base_url = base_url
  @resource = "image"
  @version = "1.0"
end

Public Instance Methods

convert_format(name, imagePath, formatToConvert) click to toggle source

Converts the format of the image. Returns the original image url and converted image url. Images are stored on the cloud and can be accessed through the urls Conversion is done based on the formatToConvert provided

@param name

- Name of the image to resize

@param imagePath

- Path of the local file to resize

@param formatToConvert

- to which file needs to be converted

@return Image object containing urls for the original and converted

images

@throws App42Exception

# File lib/imageProcessor/ImageProcessorService.rb, line 947
def convert_format(name, imagePath, formatToConvert)
  puts "convert_format Called "
  puts "Base url #{@base_url}"
  response = nil
  imageObj = nil
  imageObj = Image.new()
  util = Util.new
  util.throwExceptionIfNullOrBlank(name, "Name");
  util.throwExceptionIfNullOrBlank(imagePath, "Image Path");
  util.throwExceptionIfNullOrBlank(formatToConvert, "FormatToConvert");
  begin
    file = File.new(imagePath,"rb")
    ext = File.extname(file)
    if((ext.eql?(".jpg") == false) && (ext.eql?(".JPG") == false) && (ext.eql?(".jpeg") == false) && (ext.eql?(".JPEG") == false) && (ext.eql?(".gif") == false) && (ext.eql?(".GIF") == false) && (ext.eql?(".png") == false) && (ext.eql?(".PNG") == false))
      raise TypeError,"The Request parameters are invalid. Only file with extensions jpg, jpeg, gif and png are supported"
    end
    if((formatToConvert.eql?("jpg") == false) && (formatToConvert.eql?("JPG") == false) && (formatToConvert.eql?("jpeg") == false) && (formatToConvert.eql?("JPEG") == false) && (formatToConvert.eql?("gif") == false) && (formatToConvert.eql?("GIF") == false) && (formatToConvert.eql?("png") == false) && (formatToConvert.eql?("PNG") == false))
      raise TypeError, "The Request parameters are invalid. Supported conversion extensions are jpg, jpeg, gif and png only"
    end
    if File.file?(imagePath) == false
      raise App42Exception.new("File " + imagePath.to_s + " does not exist");
    end
    connection = App42::Connection::RESTConnection.new(@base_url)
    params = Hash.new
    query_params = Hash.new
    query_params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    params = query_params.clone
    post_params = Hash.new
    post_params.store("name", name)
    post_params.store("formatToConvert", formatToConvert)
    params = params.merge(post_params)
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/convertformat"
    response = connection.imageMultipart(signature, resource_url, query_params, params, imagePath)
    image = ImageProcessorResponseBuilder.new
    imageObj = image.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return imageObj
end
convert_format_with_stream(name, imagePath, formatToConvert) click to toggle source

Converts the format of the image. Returns the original image url and converted image url. Images are stored on the cloud and can be accessed through the urls Conversion is done based on the formatToConvert provided

@param name

- Name of the image to convert

@param imagePath

- imagePath of the local file to convert

@param formatToConvert

- to which file needs to be converted

@return Image object containing urls for the original and converted

images

@throws App42Exception

# File lib/imageProcessor/ImageProcessorService.rb, line 1012
def convert_format_with_stream(name, imagePath, formatToConvert)
  puts "convert_format_with_stream Called "
  puts "Base url #{@base_url}"
  response = nil
  imageObj = nil
  imageObj = Image.new()
  util = Util.new
  util.throwExceptionIfNullOrBlank(name, "Name");
  util.throwExceptionIfNotValidImageExtension(name, "Name");
  util.throwExceptionIfNullOrBlank(formatToConvert, "FormatToConvert");
  begin
    if((formatToConvert.eql?("jpg") == false) && (formatToConvert.eql?("JPG") == false) && (formatToConvert.eql?("jpeg") == false) && (formatToConvert.eql?("JPEG") == false) && (formatToConvert.eql?("gif") == false) && (formatToConvert.eql?("GIF") == false) && (formatToConvert.eql?("png") == false) && (formatToConvert.eql?("PNG") == false))
      raise TypeError, "The Request parameters are invalid. Supported conversion extensions are jpg, jpeg, gif and png only"
    end
    if File.file?(imagePath) == false
      raise App42Exception.new("File " + imagePath.to_s + " does not exist");
    end
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("name", name)
    params.store("formatToConvert", formatToConvert);
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/convertformat"
    response = connection.imageMultipartStream(signature, resource_url, query_params, params, imagePath)
    image = ImageProcessorResponseBuilder.new
    imageObj = image.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return imageObj
end
crop(name, imagePath, width, height, x, y) click to toggle source

Crops image based on width, height and x, y coordinates. Returns the original image url and converted image url. Images are stored in the cloud and can be accessed through the urls Resizing is done based on the width and height provided

@param name

- Name of the image to crop

@param imagePath

- Path of the local file to crop

@param width

- Width of the image to crop

@param height

- Height of the image to crop

@param x

- Coordinate X

@param y

- Coordinate Y

@return Image object containing urls for the original and converted images

@raise App42Exception

# File lib/imageProcessor/ImageProcessorService.rb, line 450
def crop(name, imagePath, width, height, x, y)
  puts "crop Called "
  puts "Base url #{@base_url}"
  response = nil
  imageObj = nil
  imageObj = Image.new()
  util = Util.new
  util.throwExceptionIfNullOrBlank(name, "Name");
  util.throwExceptionIfNullOrBlank(imagePath, "Image Path");
  util.throwExceptionIfNullOrBlank(width, "Width");
  util.throwExceptionIfNullOrBlank(height, "Height");
  util.throwExceptionIfNullOrBlank(x, "x");
  util.throwExceptionIfNullOrBlank(y, "y");
  begin
    file = File.new(imagePath,"rb")
    ext = File.extname(file)
    if((ext.eql?(".jpg") == false) && (ext.eql?(".JPG") == false) && (ext.eql?(".jpeg") == false) && (ext.eql?(".JPEG") == false) && (ext.eql?(".gif") == false) && (ext.eql?(".GIF") == false) && (ext.eql?(".png") == false) && (ext.eql?(".PNG") == false))
      raise TypeError,"The Request parameters are invalid. Only file with extensions jpg, jpeg, gif and png are supported"
    end
    if File.file?(imagePath) == false
      raise App42Exception.new(" File " + imagePath.to_s + " does not exist");
    end
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("name", name)
    params.store("width", (width.to_i).to_s + "")
    params.store("height", (height.to_i).to_s + "")
    params.store("x", (x.to_i).to_s + "")
    params.store("y", (y.to_i).to_s + "")
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/crop"
    response = connection.imageMultipart(signature, resource_url, query_params, params, imagePath)
    image = ImageProcessorResponseBuilder.new
    imageObj = image.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return imageObj
end
crop_stream(name, imagePath, width, height, x, y) click to toggle source

Crops image based on width, height and x, y coordinates via Stream. Returns the original image url and converted image url. Images are stored in the cloud and can be accessed through the urls Resizing is done based on the width and height provided

@param name

- Name of the image to crop

@param inputStream

- InputStream of the local file to crop

@param width

- Width of the image to crop

@param height

- Height of the image to crop

@param x

- Coordinate X

@param y

- Coordinate Y

@return Image object containing urls for the original and converted images

@raise App42Exception

# File lib/imageProcessor/ImageProcessorService.rb, line 521
def crop_stream(name, imagePath, width, height, x, y)
  puts "crop Called "
  puts "Base url #{@base_url}"
  response = nil
  imageObj = nil
  imageObj = Image.new()
  util = Util.new
  util.throwExceptionIfNullOrBlank(name, "Name");
  util.throwExceptionIfNotValidImageExtension(name, "Name");
  util.throwExceptionIfNullOrBlank(width, "Width");
  util.throwExceptionIfNullOrBlank(height, "Height");
  util.throwExceptionIfNullOrBlank(x, "x");
  util.throwExceptionIfNullOrBlank(y, "y");
  begin
    file = File.new(imagePath,"rb")
    ext = File.extname(file)
    if((ext.eql?(".jpg") == false) && (ext.eql?(".JPG") == false) && (ext.eql?(".jpeg") == false) && (ext.eql?(".JPEG") == false) && (ext.eql?(".gif") == false) && (ext.eql?(".GIF") == false) && (ext.eql?(".png") == false) && (ext.eql?(".PNG") == false))
      raise TypeError,"The Request parameters are invalid. Only file with extensions jpg, jpeg, gif and png are supported"
    end
    if File.file?(imagePath) == false
      raise App42Exception.new(" File " + imagePath.to_s + " does not exist");
    end
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("name", name)
    params.store("width", (width.to_i).to_s + "")
    params.store("height", (height.to_i).to_s + "")
    params.store("x", (x.to_i).to_s + "")
    params.store("y", (y.to_i).to_s + "")
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/crop"
    response = connection.imageMultipartStream(signature, resource_url, query_params, params, imagePath)
    image = ImageProcessorResponseBuilder.new
    imageObj = image.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return imageObj
end
resize(name, imagePath, width, height) click to toggle source

Resize image. Returns the original image url and converted image url. Images are stored on the cloud and can be accessed through the urls Resizing is done based on the width and height provided

@param name

- Name of the image to resize

@param imagePath

- Path of the local file to resize

@param width

- Width of the image to resize

@param height

- Height of the image to resize

@return Image object containing urls for the original and converted images

@raise App42Exception

# File lib/imageProcessor/ImageProcessorService.rb, line 61
def resize(name, imagePath, width, height)
  puts "resize Called "
  puts "Base url #{@base_url}"
  response = nil
  imageObj = nil
  imageObj = Image.new()
  util = Util.new
  util.throwExceptionIfNullOrBlank(name, "Name");
  util.throwExceptionIfNullOrBlank(imagePath, "Image Path");
  util.throwExceptionIfNullOrBlank(width, "Width");
  util.throwExceptionIfNullOrBlank(height, "Height");
  begin
    file = File.new(imagePath,"rb")
    ext = File.extname(file)
    if((ext.eql?(".jpg") == false) && (ext.eql?(".JPG") == false) && (ext.eql?(".jpeg") == false) && (ext.eql?(".JPEG") == false) && (ext.eql?(".gif") == false) && (ext.eql?(".GIF") == false) && (ext.eql?(".png") == false) && (ext.eql?(".PNG") == false))
      raise TypeError,"The Request parameters are invalid. Only file with extensions jpg, jpeg, gif and png are supported"
    end
    if File.file?(imagePath) == false
      raise App42Exception.new(" File " + imagePath.to_s + " does not exist");
    end
    connection = App42::Connection::RESTConnection.new(@base_url)
    params = Hash.new
    query_params = Hash.new
    query_params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc
    }
    params = query_params.clone
    post_params = Hash.new
    post_params.store("name", name)
    post_params.store("width", width.to_s + "")
    post_params.store("height", height.to_s + "")
    params = params.merge(post_params)
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/resize"
    response = connection.imageMultipart(signature, resource_url, query_params, params, imagePath)
    image = ImageProcessorResponseBuilder.new
    imageObj = image.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return imageObj
end
resize_by_percentage(name, imagePath, percentage) click to toggle source

Resize image by Percentage. Returns the original image url and converted image url. Images are stored in the cloud and can be accessed through the urls Resizing is done based on the width and height provided

@param name

- Name of the image to resize

@param imagePath

- Path of the local file to resize

@param percentage

- Percentage to which image has to be resized

@return Image object containing urls for the original and converted images

@raise App42Exception

# File lib/imageProcessor/ImageProcessorService.rb, line 586
def resize_by_percentage(name, imagePath, percentage)
  puts "resizeByPercentage Called "
  puts "Base url #{@base_url}"
  response = nil
  imageObj = nil
  imageObj = Image.new()
  util = Util.new
  util.throwExceptionIfNullOrBlank(name, "Name");
  util.throwExceptionIfNullOrBlank(imagePath, "Image Path");
  util.throwExceptionIfNullOrBlank(percentage, "Percentage");
  begin
    file = File.new(imagePath,"rb")
    ext = File.extname(file)
    if((ext.eql?(".jpg") == false) && (ext.eql?(".JPG") == false) && (ext.eql?(".jpeg") == false) && (ext.eql?(".JPEG") == false) && (ext.eql?(".gif") == false) && (ext.eql?(".GIF") == false) && (ext.eql?(".png") == false) && (ext.eql?(".PNG") == false))
      raise TypeError,"The Request parameters are invalid. Only file with extensions jpg, jpeg, gif and png are supported"
    end
    if File.file?(imagePath) == false
      raise App42Exception.new("File " + imagePath.to_s + " does not exist");
    end
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("name", name)
    params.store("percentage", (percentage.to_f).to_s + "")
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/resizePercentage"
    response = connection.imageMultipart(signature, resource_url, query_params, params, imagePath)
    image = ImageProcessorResponseBuilder.new
    imageObj = image.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return imageObj
end
resize_by_percentage_by_stream(name, imagePath, percentage) click to toggle source

Resize image by Percentage via Stream. Returns the original image url and converted image url. Images are stored in the cloud and can be accessed through the urls Resizing is done based on the width and height provided

@param name

- Name of the image to resize

@param inputStream

- InputStream of the local file to resize

@param percentage

- Percentage to which image has to be resized

@return Image object containing urls for the original and converted images

@raise App42Exception

# File lib/imageProcessor/ImageProcessorService.rb, line 645
def resize_by_percentage_by_stream(name, imagePath, percentage)
  puts "resizeByPercentage Called "
  puts "Base url #{@base_url}"
  response = nil
  imageObj = nil
  imageObj = Image.new()
  util = Util.new
  util.throwExceptionIfNullOrBlank(name, "Name");
  util.throwExceptionIfNotValidImageExtension(name, "Name");
  util.throwExceptionIfNullOrBlank(percentage, "Percentage");
  begin
    file = File.new(imagePath,"rb")
    ext = File.extname(file)
    if((ext.eql?(".jpg") == false) && (ext.eql?(".JPG") == false) && (ext.eql?(".jpeg") == false) && (ext.eql?(".JPEG") == false) && (ext.eql?(".gif") == false) && (ext.eql?(".GIF") == false) && (ext.eql?(".png") == false) && (ext.eql?(".PNG") == false))
      raise TypeError,"The Request parameters are invalid. Only file with extensions jpg, jpeg, gif and png are supported"
    end
    if File.file?(imagePath) == false
      raise App42Exception.new("File " + imagePath.to_s + " does not exist");
    end
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("name", name)
    params.store("percentage", (percentage.to_f).to_s + "")
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/resizePercentage"
    response = connection.imageMultipartStream(signature, resource_url, query_params, params, imagePath)
    image = ImageProcessorResponseBuilder.new
    imageObj = image.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return imageObj
end
resize_stream(name, imagePath, width, height) click to toggle source

Resize image via Stream. Returns the original image url and converted image url. Images are stored on the cloud and can be accessed through the urls Resizing is done based on the width and height provided

@param name

- Name of the image to resize

@param inputStream

- InputStream of the local file to resize

@param width

- Width of the image to resize

@param height

- Height of the image to resize

@return Image object containing urls for the original and converted images

@raise App42Exception

# File lib/imageProcessor/ImageProcessorService.rb, line 127
def resize_stream(name, imagePath, width, height)
  puts "resize stream Called "
  puts "Base url #{@base_url}"
  response = nil
  imageObj = nil
  imageObj = Image.new()
  util = Util.new
  util.throwExceptionIfNullOrBlank(name, "Name");
  util.throwExceptionIfNotValidImageExtension(name, "Name");
  util.throwExceptionIfNullOrBlank(width, "Width");
  util.throwExceptionIfNullOrBlank(height, "Height");
  begin
    file = File.new(imagePath,"rb")
    ext = File.extname(file)
    if((ext.eql?(".jpg") == false) && (ext.eql?(".JPG") == false) && (ext.eql?(".jpeg") == false) && (ext.eql?(".JPEG") == false) && (ext.eql?(".gif") == false) && (ext.eql?(".GIF") == false) && (ext.eql?(".png") == false) && (ext.eql?(".PNG") == false))
      raise TypeError,"The Request parameters are invalid. Only file with extensions jpg, jpeg, gif and png are supported"
    end
    if File.file?(imagePath) == false
      raise App42Exception.new(" File " + imagePath.to_s + " does not exist");
    end
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("name", name)
    params.store("width", width.to_s + "")
    params.store("height", height.to_s + "")
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/resize"
    response = connection.imageMultipartStream(signature, resource_url, query_params, params, imagePath)
    image = ImageProcessorResponseBuilder.new
    imageObj = image.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return imageObj
end
scale(name, imagePath, width, height) click to toggle source

Scales the image based on width and height. Returns the original image url and converted image url. Images are stored in the cloud and can be accessed through the urls Resizing is done based on the width and height provided

@param name

- Name of the image to scale

@param imagePath

- Path of the local file to scale

@param width

- Width of the image to scale

@param height

- Height of the image to scale

@return Image object containing urls for the original and converted images

@raise App42Exception

# File lib/imageProcessor/ImageProcessorService.rb, line 320
def scale(name, imagePath, width, height)
  puts "scale Called "
  puts "Base url #{@base_url}"
  response = nil
  imageObj = nil
  imageObj = Image.new()
  util = Util.new
  util.throwExceptionIfNullOrBlank(name, "Name");
  util.throwExceptionIfNullOrBlank(imagePath, "Image Path");
  util.throwExceptionIfNullOrBlank(width, "Width");
  util.throwExceptionIfNullOrBlank(height, "Height");
  begin
    file = File.new(imagePath,"rb")
    ext = File.extname(file)
    if((ext.eql?(".jpg") == false) && (ext.eql?(".JPG") == false) && (ext.eql?(".jpeg") == false) && (ext.eql?(".JPEG") == false) && (ext.eql?(".gif") == false) && (ext.eql?(".GIF") == false) && (ext.eql?(".png") == false) && (ext.eql?(".PNG") == false))
      raise TypeError,"The Request parameters are invalid. Only file with extensions jpg, jpeg, gif and png are supported"
    end
    if File.file?(imagePath) == false
      raise App42Exception.new(" File " + imagePath.to_s + " does not exist");
    end
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("name", name)
    params.store("width", (width.to_i).to_s + "")
    params.store("height", (height.to_i).to_s + "")
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/scale"
    response = connection.imageMultipart(signature, resource_url, query_params, params, imagePath)
    image = ImageProcessorResponseBuilder.new
    imageObj = image.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return imageObj
end
scale_by_percentage(name, imagePath, percentage) click to toggle source

Scales the image by Percentage. Returns the original image url and converted image url. Images are stored in the cloud and can be accessed through the urls Resizing is done based on the width and height provided

@param name

- Name of the image file to scale

@param imagePath

- Path of the local file to scale

@param percentage

- Percentage to which image has to be scaled

@return Image object containing urls for the original and converted images

@raise App42Exception

# File lib/imageProcessor/ImageProcessorService.rb, line 829
def scale_by_percentage(name, imagePath, percentage)
  puts "scaleByPercentage Called "
  puts "Base url #{@base_url}"
  response = nil
  imageObj = nil
  imageObj = Image.new()
  util = Util.new
  util.throwExceptionIfNullOrBlank(name, "Name");
  util.throwExceptionIfNullOrBlank(imagePath, "Image Path");
  util.throwExceptionIfNullOrBlank(percentage, "Percentage");
  begin
    file = File.new(imagePath,"rb")
    ext = File.extname(file)
    if((ext.eql?(".jpg") == false) && (ext.eql?(".JPG") == false) && (ext.eql?(".jpeg") == false) && (ext.eql?(".JPEG") == false) && (ext.eql?(".gif") == false) && (ext.eql?(".GIF") == false) && (ext.eql?(".png") == false) && (ext.eql?(".PNG") == false))
      raise TypeError,"The Request parameters are invalid. Only file with extensions jpg, jpeg, gif and png are supported"
    end
    if File.file?(imagePath) == false
      raise App42Exception.new("File " + imagePath.to_s + " does not exist");
    end
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("name", name)
    params.store("percentage", (percentage.to_f).to_s + "")
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/scalePercentage"
    response = connection.imageMultipart(signature, resource_url, query_params, params, imagePath)
    image = ImageProcessorResponseBuilder.new
    imageObj = image.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return imageObj
end
scale_by_percentage_stream(name, imagePath, percentage) click to toggle source

Scales the image by Percentage via Stream. Returns the original image url and converted image url. Images are stored in the cloud and can be accessed through the urls Resizing is done based on the width and height provided

@param name

- Name of the image file to scale

@param inputStream

- InputStream of the local file to scale

@param percentage

- Percentage to which image has to be scaled

@return Image object containing urls for the original and converted images

@raise App42Exception

# File lib/imageProcessor/ImageProcessorService.rb, line 888
def scale_by_percentage_stream(name, imagePath, percentage)
  puts "scaleByPercentage Called "
  puts "Base url #{@base_url}"
  response = nil
  imageObj = nil
  imageObj = Image.new()
  util = Util.new
  util.throwExceptionIfNullOrBlank(name, "Name");
  util.throwExceptionIfNotValidImageExtension(name, "Name");
  util.throwExceptionIfNullOrBlank(percentage, "Percentage");
  begin
    file = File.new(imagePath,"rb")
    ext = File.extname(file)
    if((ext.eql?(".jpg") == false) && (ext.eql?(".JPG") == false) && (ext.eql?(".jpeg") == false) && (ext.eql?(".JPEG") == false) && (ext.eql?(".gif") == false) && (ext.eql?(".GIF") == false) && (ext.eql?(".png") == false) && (ext.eql?(".PNG") == false))
      raise TypeError,"The Request parameters are invalid. Only file with extensions jpg, jpeg, gif and png are supported"
    end
    if File.file?(imagePath) == false
      raise App42Exception.new("File " + imagePath.to_s + " does not exist");
    end
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("name", name)
    params.store("percentage", (percentage.to_f).to_s + "")
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/scalePercentage"
    response = connection.imageMultipartStream(signature, resource_url, query_params, params, imagePath)
    image = ImageProcessorResponseBuilder.new
    imageObj = image.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return imageObj
end
scale_stream(name, imagePath, width, height) click to toggle source

Scales the image based on width and height via Stream. Returns the original image url and converted image url. Images are stored in the cloud and can be accessed through the urls Resizing is done based on the width and height provided

@param name

- Name of the image to scale

@param inputStream

- InputStream of the local file to scale

@param width

- Width of the image to scale

@param height

- Height of the image to scale

@return Image object containing urls for the original and converted images

@raise App42Exception

# File lib/imageProcessor/ImageProcessorService.rb, line 383
def scale_stream(name, imagePath, width, height)
  puts "scale Called "
  puts "Base url #{@base_url}"
  response = nil
  imageObj = nil
  imageObj = Image.new()
  util = Util.new
  util.throwExceptionIfNullOrBlank(name, "Name");
  util.throwExceptionIfNotValidImageExtension(name, "Name");
  util.throwExceptionIfNullOrBlank(width, "Width");
  util.throwExceptionIfNullOrBlank(height, "Height");
  begin
    file = File.new(imagePath,"rb")
    ext = File.extname(file)
    if((ext.eql?(".jpg") == false) && (ext.eql?(".JPG") == false) && (ext.eql?(".jpeg") == false) && (ext.eql?(".JPEG") == false) && (ext.eql?(".gif") == false) && (ext.eql?(".GIF") == false) && (ext.eql?(".png") == false) && (ext.eql?(".PNG") == false))
      raise TypeError,"The Request parameters are invalid. Only file with extensions jpg, jpeg, gif and png are supported"
    end
    if File.file?(imagePath) == false
      raise App42Exception.new(" File " + imagePath.to_s + " does not exist");
    end
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("name", name)
    params.store("width", (width.to_i).to_s + "")
    params.store("height", (height.to_i).to_s + "")
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/scale"
    response = connection.imageMultipartStream(signature, resource_url, query_params, params, imagePath)
    image = ImageProcessorResponseBuilder.new
    imageObj = image.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return imageObj
end
thumbnail(name, imagePath, width, height) click to toggle source

Creates a thumbnail of the image. There is a difference between thumbnail and resize The thumbnail operation is optimized for speed, it removes information of the image which is not necessary for a thumbnail e.g header information. Returns the original image url and converted image url. Images are stored on the cloud and can be accessed through the urls Resizing is done based on the width and height provided

@param name

- Name of the image file for which thumbnail has to be created

@param imagePath

- Path of the local file whose thumbnail has to be created

@param width

- Width of the image for thumbnail

@param height

- Height of the image for thumbnail

@return Image object containing urls for the original and converted images

@raise App42Exception

# File lib/imageProcessor/ImageProcessorService.rb, line 192
def thumbnail(name, imagePath, width, height)
  puts "thumbnail Called "
  puts "Base url #{@base_url}"
  response = nil
  imageObj = nil
  imageObj = Image.new()
  util = Util.new
  util.throwExceptionIfNullOrBlank(name, "Name");
  util.throwExceptionIfNullOrBlank(imagePath, "Image Path");
  util.throwExceptionIfNullOrBlank(width, "Width");
  util.throwExceptionIfNullOrBlank(height, "Height");
  begin
    file = File.new(imagePath,"rb")
    ext = File.extname(file)
    if((ext.eql?(".jpg") == false) && (ext.eql?(".JPG") == false) && (ext.eql?(".jpeg") == false) && (ext.eql?(".JPEG") == false) && (ext.eql?(".gif") == false) && (ext.eql?(".GIF") == false) && (ext.eql?(".png") == false) && (ext.eql?(".PNG") == false))
      raise TypeError,"The Request parameters are invalid. Only file with extensions jpg, jpeg, gif and png are supported"
    end
    if File.file?(imagePath) == false
      raise App42Exception.new(" File " + imagePath.to_s + " does not exist");
    end
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("name", name)
    params.store("width", width.to_s + "")
    params.store("height", height.to_s + "")
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/thumbnail"
    response = connection.imageMultipart(signature, resource_url, query_params, params, imagePath)
    image = ImageProcessorResponseBuilder.new
    imageObj = image.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return imageObj
end
thumbnail_by_percentage(name, imagePath, percentage) click to toggle source

Creates a thumbnail of the image by Percentage. There is a difference between thumbnail and resize The thumbnail operation is optimized for speed removes information of the image which is not necessary for a thumbnail to reduce size e.g header information. Returns the original image url and converted image url. Images are stored in the cloud and can be accessed through the urls Resizing is done based on the width and height provided

@param name

- Name of the image file for which thumbnail has to be created

@param imagePath

- Path of the local file whose thumbnail has to be created

@param percentage

- Percentage for thumbnail

@return Image object containing urls for the original and converted images

@raise App42Exception

# File lib/imageProcessor/ImageProcessorService.rb, line 706
def thumbnail_by_percentage(name, imagePath, percentage)
  puts "thumbnailByPercentage Called "
  puts "Base url #{@base_url}"
  response = nil
  imageObj = nil
  imageObj = Image.new()
  util = Util.new
  util.throwExceptionIfNullOrBlank(name, "Name");
  util.throwExceptionIfNullOrBlank(imagePath, "Image Path");
  util.throwExceptionIfNullOrBlank(percentage, "Percentage");
  begin
    file = File.new(imagePath,"rb")
    ext = File.extname(file)
    if((ext.eql?(".jpg") == false) && (ext.eql?(".JPG") == false) && (ext.eql?(".jpeg") == false) && (ext.eql?(".JPEG") == false) && (ext.eql?(".gif") == false) && (ext.eql?(".GIF") == false) && (ext.eql?(".png") == false) && (ext.eql?(".PNG") == false))
      raise TypeError,"The Request parameters are invalid. Only file with extensions jpg, jpeg, gif and png are supported"
    end
    if File.file?(imagePath) == false
      raise App42Exception.new(" File " + imagePath.to_s + " does not exist");
    end
    connection = App42::Connection::RESTConnection.new(@base_url)
    params = Hash.new
    query_params = Hash.new
    query_params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    params = query_params.clone
    post_params = Hash.new
    post_params.store("name", name)
    post_params.store("percentage", (percentage.to_f).to_s + "")
    params = params.merge(post_params)
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/thumbnailPercentage"
    response = connection.imageMultipart(signature, resource_url, query_params, params, imagePath)
    image = ImageProcessorResponseBuilder.new
    imageObj = image.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return imageObj
end
thumbnail_by_percentage_stream(name, imagePath, percentage) click to toggle source

Creates a thumbnail of the image by Percentage via Stream. There is a difference between thumbnail and resize The thumbnail operation is optimized for speed removes information of the image which is not necessary for a thumbnail to reduce size e.g header information. Returns the original image url and converted image url. Images are stored in the cloud and can be accessed through the urls Resizing is done based on the width and height provided

@param name

- Name of the image file for which thumbnail has to be created

@param inputStream

- InputStream of the local file whose thumbnail has to be created

@param percentage

- Percentage for thumbnail

@return Image object containing urls for the original and converted images

@raise App42Exception

# File lib/imageProcessor/ImageProcessorService.rb, line 770
def thumbnail_by_percentage_stream(name, imagePath, percentage)
  puts "thumbnailByPercentage Called "
  puts "Base url #{@base_url}"
  response = nil
  imageObj = nil
  imageObj = Image.new()
  util = Util.new
  util.throwExceptionIfNullOrBlank(name, "Name");
  util.throwExceptionIfNotValidImageExtension(name, "Name");
  util.throwExceptionIfNullOrBlank(percentage, "Percentage");
  begin
    file = File.new(imagePath,"rb")
    ext = File.extname(file)
    if((ext.eql?(".jpg") == false) && (ext.eql?(".JPG") == false) && (ext.eql?(".jpeg") == false) && (ext.eql?(".JPEG") == false) && (ext.eql?(".gif") == false) && (ext.eql?(".GIF") == false) && (ext.eql?(".png") == false) && (ext.eql?(".PNG") == false))
      raise TypeError,"The Request parameters are invalid. Only file with extensions jpg, jpeg, gif and png are supported"
    end
    if File.file?(imagePath) == false
      raise App42Exception.new(" File " + imagePath.to_s + " does not exist");
    end
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("name", name)
    params.store("percentage", (percentage.to_f).to_s + "")
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/thumbnailPercentage"
    response = connection.imageMultipartStream(signature, resource_url, query_params, params, imagePath)
    image = ImageProcessorResponseBuilder.new
    imageObj = image.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return imageObj
end
thumbnail_stream(name, imagePath, width, height) click to toggle source

Creates a thumbnail of the image via Stream. There is a difference between thumbnail and resize The thumbnail operation is optimized for speed, it removes information of the image which is not necessary for a thumbnail e.g header information. Returns the original image url and converted image url. Images are stored on the cloud and can be accessed through the urls Resizing is done based on the width and height provided

@param name

- Name of the image file for which thumbnail has to be created

@param inputStream

- InputStream of the local file whose thumbnail has to be created

@param width

- Width of the image for thumbnail

@param height

- Height of the image for thumbnail

@return Image object containing urls for the original and converted images

@raise App42Exception

# File lib/imageProcessor/ImageProcessorService.rb, line 257
def thumbnail_stream(name, imagePath, width, height)
  puts "thumbnail Called "
  puts "Base url #{@base_url}"
  response = nil
  imageObj = nil
  imageObj = Image.new()
  util = Util.new
  util.throwExceptionIfNullOrBlank(name, "Name");
  util.throwExceptionIfNotValidImageExtension(name, "Name");
  util.throwExceptionIfNullOrBlank(width, "Width");
  util.throwExceptionIfNullOrBlank(height, "Height");
  begin
    file = File.new(imagePath,"rb")
    ext = File.extname(file)
    if((ext.eql?(".jpg") == false) && (ext.eql?(".JPG") == false) && (ext.eql?(".jpeg") == false) && (ext.eql?(".JPEG") == false) && (ext.eql?(".gif") == false) && (ext.eql?(".GIF") == false) && (ext.eql?(".png") == false) && (ext.eql?(".PNG") == false))
      raise TypeError,"The Request parameters are invalid. Only file with extensions jpg, jpeg, gif and png are supported"
    end
    if File.file?(imagePath) == false
      raise App42Exception.new(" File " + imagePath.to_s + " does not exist");
    end
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("name", name)
    params.store("width", width.to_s + "")
    params.store("height", height.to_s + "")
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/thumbnail"
    response = connection.imageMultipartStream(signature, resource_url, query_params, params, imagePath)
    image = ImageProcessorResponseBuilder.new
    imageObj = image.buildResponse(response)
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return imageObj
end