Class: Riiif::File

Inherits:
Object
  • Object
show all
Defined in:
app/models/riiif/file.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_path, tempfile = nil) ⇒ File

Returns a new instance of File.

Parameters:

  • input_path (String)

    The location of an image file



17
18
19
20
# File 'app/models/riiif/file.rb', line 17

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

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'app/models/riiif/file.rb', line 3

def path
  @path
end

Class Method Details

.info_extractor_classObject

TODO: add alternative that uses kdu_jp2info



8
9
10
11
12
13
14
# File 'app/models/riiif/file.rb', line 8

def self.info_extractor_class
  if Riiif.use_vips?
    VipsInfoExtractor
  else
    ImageMagickInfoExtractor
  end
end

Instance Method Details

#extract(transformation, image_info = info) ⇒ String

Returns the processed image data.

Parameters:

  • transformation (Transformation)
  • image_info (ImageInformation) (defaults to: info)

Returns:

  • (String)

    the processed image data



25
26
27
# File 'app/models/riiif/file.rb', line 25

def extract(transformation, image_info = info)
  transformer.transform(path, image_info, transformation)
end

#infoObject



39
40
41
# File 'app/models/riiif/file.rb', line 39

def info
  @info ||= info_extractor.extract
end

#info_extractorObject



43
44
45
# File 'app/models/riiif/file.rb', line 43

def info_extractor
  @info_extractor ||= info_extractor_class.new(path)
end

#transformerObject



29
30
31
32
33
34
35
36
37
# File 'app/models/riiif/file.rb', line 29

def transformer
  if Riiif.use_vips?
    VipsTransformer
  elsif Riiif.kakadu_enabled? && path.ends_with?('.jp2')
    KakaduTransformer
  else
    ImagemagickTransformer
  end
end