Class: Spraycan::Workers::Manipulate

Inherits:
Bottle::Foreman
  • Object
show all
Defined in:
lib/spraycan/workers/manipulate.rb

Instance Method Summary collapse

Instance Method Details

#get_image(image_path) ⇒ Object



32
33
34
35
36
# File 'lib/spraycan/workers/manipulate.rb', line 32

def get_image(image_path)
  Publisher::S3::Download.file_content(image_path)
rescue
  raise "Failed to download #{image_path} from S3"
end

#process(payload) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/spraycan/workers/manipulate.rb', line 5

def process(payload)
  puts "Starting Manipulate#process. Payload - #{payload.inspect}\n"

  crop    = payload[:crop]
  size    = payload[:size]
  s3_path = payload[:s3_path]

  return failure('s3_path must be specified') unless s3_path
  return failure('crop not set') unless crop
  return failure('size not set') unless size

  image = get_image(s3_path)

  response = Rmagick.new.resized_crop_mask(image, crop, size)

  save_to_cloud(response[:image], s3_path)

  GC.start #free the memory
  return success({})
rescue => e
  return failure 'Fatal error handling image: ' + e.message
end

#save_to_cloud(image, s3_path) ⇒ Object



28
29
30
# File 'lib/spraycan/workers/manipulate.rb', line 28

def save_to_cloud(image, s3_path)
  Publisher::S3::Upload.upload(image, s3_path)
end