Method: App42::ImageProcessor::ImageProcessorService#thumbnail

Defined in:
lib/imageProcessor/ImageProcessorService.rb

#thumbnail(name, imagePath, width, height) ⇒ Object

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

Parameters:

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

  • imagePath
    • Path of the local file whose thumbnail has to be created

  • width
    • Width of the image for thumbnail

  • height
    • Height of the image for thumbnail

Returns:

  • Image object containing urls for the original and converted images

Raises:

  • App42Exception



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# 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