Class: Riiif::File
- Inherits:
-
Object
- Object
- Riiif::File
- Includes:
- ActiveSupport::Benchmarkable, Open3
- Defined in:
- app/models/riiif/file.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #extract(options) ⇒ Object
- #info ⇒ Object
-
#initialize(input_path, tempfile = nil) ⇒ File
constructor
A new instance of File.
Constructor Details
#initialize(input_path, tempfile = nil) ⇒ File
Returns a new instance of File.
12 13 14 15 |
# File 'app/models/riiif/file.rb', line 12 def initialize(input_path, tempfile = nil) @path = input_path @tempfile = tempfile # ensures that the tempfile will stick around until this file is garbage collected. end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'app/models/riiif/file.rb', line 7 def path @path end |
Class Method Details
.create(ext = nil, _validate = true, &block) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/models/riiif/file.rb', line 25 def self.create(ext = nil, _validate = true, &block) tempfile = Tempfile.new(['mini_magick', ext.to_s.downcase]) tempfile.binmode block.call(tempfile) tempfile.close image = new(tempfile.path, tempfile) ensure tempfile.close if tempfile end |
.read(stream, ext) ⇒ Object
17 18 19 20 21 22 23 |
# File 'app/models/riiif/file.rb', line 17 def self.read(stream, ext) create(ext) do |f| while chunk = stream.read(8192) f.write(chunk) end end end |
Instance Method Details
#extract(options) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/models/riiif/file.rb', line 37 def extract() command = 'convert' command << " -crop #{[:crop]}" if [:crop] command << " -resize #{[:size]}" if [:size] if [:rotation] command << " -virtual-pixel white +distort srt #{[:rotation]}" end case [:quality] when 'grey' command << ' -colorspace Gray' when 'bitonal' command << ' -colorspace Gray' command << ' -type Bilevel' end command << " #{path} #{[:format]}:-" execute(command) end |
#info ⇒ Object
57 58 59 60 61 |
# File 'app/models/riiif/file.rb', line 57 def info return @info if @info height, width = execute("identify -format %hx%w #{path}").split('x') @info = { height: Integer(height), width: Integer(width) } end |