Class: App42::ImageProcessor::ImageProcessorService

Inherits:
Object
  • Object
show all
Defined in:
lib/imageProcessor/ImageProcessorService.rb

Overview

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 Also:

Instance Method Summary collapse

Constructor Details

#initialize(api_key, secret_key, base_url) ⇒ ImageProcessorService

this is a constructor that takes

Parameters:

  • apiKey
  • secretKey
  • baseURL


33
34
35
36
37
38
39
40
# 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

Instance Method Details

#convert_format(name, imagePath, formatToConvert) ⇒ Object

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

Parameters:

  • name
    • Name of the image to resize

  • imagePath
    • Path of the local file to resize

  • formatToConvert
    • to which file needs to be converted

Returns:

  • Image object containing urls for the original and converted images



947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
# 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) ⇒ Object

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

Parameters:

  • name
    • Name of the image to convert

  • imagePath
    • imagePath of the local file to convert

  • formatToConvert
    • to which file needs to be converted

Returns:

  • Image object containing urls for the original and converted images



1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
# 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) ⇒ Object

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

Parameters:

  • name
    • Name of the image to crop

  • imagePath
    • Path of the local file to crop

  • width
    • Width of the image to crop

  • height
    • Height of the image to crop

  • x
    • Coordinate X

  • y
    • Coordinate Y

Returns:

  • Image object containing urls for the original and converted images

Raises:

  • App42Exception



450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
# 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) ⇒ Object

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

Parameters:

  • name
    • Name of the image to crop

  • inputStream
    • InputStream of the local file to crop

  • width
    • Width of the image to crop

  • height
    • Height of the image to crop

  • x
    • Coordinate X

  • y
    • Coordinate Y

Returns:

  • Image object containing urls for the original and converted images

Raises:

  • App42Exception



521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
# 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) ⇒ Object

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

Parameters:

  • name
    • Name of the image to resize

  • imagePath
    • Path of the local file to resize

  • width
    • Width of the image to resize

  • height
    • Height of the image to resize

Returns:

  • Image object containing urls for the original and converted images

Raises:

  • App42Exception



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# 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) ⇒ Object

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

Parameters:

  • name
    • Name of the image to resize

  • imagePath
    • Path of the local file to resize

  • percentage
    • Percentage to which image has to be resized

Returns:

  • Image object containing urls for the original and converted images

Raises:

  • App42Exception



586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
# 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) ⇒ Object

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

Parameters:

  • name
    • Name of the image to resize

  • inputStream
    • InputStream of the local file to resize

  • percentage
    • Percentage to which image has to be resized

Returns:

  • Image object containing urls for the original and converted images

Raises:

  • App42Exception



645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
# 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) ⇒ Object

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

Parameters:

  • name
    • Name of the image to resize

  • inputStream
    • InputStream of the local file to resize

  • width
    • Width of the image to resize

  • height
    • Height of the image to resize

Returns:

  • Image object containing urls for the original and converted images

Raises:

  • App42Exception



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# 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) ⇒ Object

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

Parameters:

  • name
    • Name of the image to scale

  • imagePath
    • Path 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



320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# 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) ⇒ Object

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

Parameters:

  • name
    • Name of the image file to scale

  • imagePath
    • Path of the local file to scale

  • percentage
    • Percentage to which image has to be scaled

Returns:

  • Image object containing urls for the original and converted images

Raises:

  • App42Exception



829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
# 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) ⇒ Object

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

Parameters:

  • name
    • Name of the image file to scale

  • inputStream
    • InputStream of the local file to scale

  • percentage
    • Percentage to which image has to be scaled

Returns:

  • Image object containing urls for the original and converted images

Raises:

  • App42Exception



888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
# 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) ⇒ 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

#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

#thumbnail_by_percentage(name, imagePath, percentage) ⇒ Object

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

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

  • percentage
    • Percentage for thumbnail

Returns:

  • Image object containing urls for the original and converted images

Raises:

  • App42Exception



706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
# 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) ⇒ Object

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

Parameters:

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

  • inputStream
    • InputStream of the local file whose thumbnail has to be created

  • percentage
    • Percentage for thumbnail

Returns:

  • Image object containing urls for the original and converted images

Raises:

  • App42Exception



770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
# 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) ⇒ Object

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

Parameters:

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

  • inputStream
    • InputStream 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



257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# 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