Class: Flickrage::Worker::Resize
- Defined in:
- lib/flickrage/worker/resize.rb
Constant Summary collapse
- MIN_IMAGE_SIZE =
100- MAX_IMAGE_SIZE =
500
Constants inherited from Base
Base::MAX_ASK_ERRORS, Base::PRINT_IMAGE_HEADERS, Base::PRINT_IMAGE_HEADERS_LITE
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
Methods included from Helpers::Tty
Methods included from Helpers::Log
Constructor Details
This class inherits a constructor from Flickrage::Worker::Base
Instance Method Details
#call(image_list) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/flickrage/worker/resize.rb', line 8 def call(image_list) raise Flickrage::ResizeError, 'Not enough images for resize' if image_list.downloaded&.size < 1 speaker.add_padding logger.debug('Resizing process') init_crop_value('width') init_crop_value('height') @spin = spinner(message: 'Resizing images') files = image_list.downloaded.map do |image| Concurrent .future(thread_pool) do update_spin(spin, title: "Resizing image #{image.id}") service.run(image) end .then do |r| update_spin(spin, title: "Resized image #{r.id}") r end .rescue { |_| nil } end result = Concurrent.zip(*files).value result = result.compact.flatten if result total = result.count(&:resized?) if total > 2 spin.success else spin.error('(failed: Not enough images resized)') raise Flickrage::ResizeError end speaker.add_padding logger.info("Resized #{result.count(&:resized?)} images:") speaker.print_table([PRINT_IMAGE_HEADERS_LITE + %w(path resized?)] + result.map do |i| [i.keyword, i.id, i.resize_path, i.resized?] end) image_list.merge_images result ensure clean_thread_pool spin&.stop end |