2018-09-20 23:25:39 +00:00
|
|
|
|
|
|
|
# Actor for cropping png
|
|
|
|
module Webgalien
|
|
|
|
class CropPngActor
|
|
|
|
include Celluloid
|
|
|
|
|
2018-10-11 07:58:38 +00:00
|
|
|
def initialize(output_path)
|
|
|
|
@output_path = output_path
|
|
|
|
end
|
|
|
|
|
2018-09-20 23:25:39 +00:00
|
|
|
def perform(work_future)
|
|
|
|
work = work_future.value
|
|
|
|
work.shift!
|
|
|
|
|
|
|
|
input_path = work.input[:path]
|
|
|
|
bbox = work.input[:bbox]
|
2018-10-11 07:58:38 +00:00
|
|
|
output_path = File.join(@output_path, 'crop-' + work.id + '.png')
|
2018-09-20 23:25:39 +00:00
|
|
|
|
|
|
|
puts "(#{work.id}) cropping capture".green
|
|
|
|
system 'convert ' \
|
|
|
|
"-crop #{bbox[:w]}x#{bbox[:h]}+#{bbox[:x]}+#{bbox[:y]} " \
|
|
|
|
"#{input_path} #{output_path}"
|
|
|
|
|
|
|
|
work.output = { path: output_path }
|
|
|
|
work
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|