Class: Mindee::V2::FileOperation::CropFiles

Inherits:
Array
  • Object
show all
Defined in:
lib/mindee/v2/file_operations/crop_files.rb

Overview

Collection of cropped files.

Instance Method Summary collapse

Instance Method Details

#save_all_to_disk(path, prefix: 'crop', file_format: nil) ⇒ Object

Save all extracted crops to disk.

Parameters:

  • path (String, Pathname)

    Path to save the extracted crops to.

  • prefix (String) (defaults to: 'crop')

    Prefix to add to the filename, defaults to 'crop'.

  • file_format (String, nil) (defaults to: nil)

    File format to save the crops as, defaults to jpg if nil.]



13
14
15
16
17
18
19
20
21
# File 'lib/mindee/v2/file_operations/crop_files.rb', line 13

def save_all_to_disk(path, prefix: 'crop', file_format: nil)
  FileUtils.mkdir_p(path)
  each.with_index(1) do |crop, idx|
    filename = "#{prefix}_#{format('%03d', idx)}.jpg"
    file_path = File.join(path.to_s, filename)

    crop.write_to_file(file_path, file_format)
  end
end