Method: App42::ImageProcessor::ImageProcessorService#scale_stream

Defined in:
lib/imageProcessor/ImageProcessorService.rb

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

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

Parameters:

  • name
    • Name of the image to scale

  • inputStream
    • InputStream of the local file to scale

  • width
    • Width of the image to scale

  • height
    • Height of the image to scale

Returns:

  • Image object containing urls for the original and converted images

Raises:

  • App42Exception



383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
# 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