Sha256: d1e7a7c4a3159748517362242a675d45937f4673dda741a79e3adfc22821acfc

Contents?: true

Size: 1.01 KB

Versions: 5

Compression:

Stored size: 1.01 KB

Contents

module Riiif
  class File
    attr_reader :path

    class_attribute :info_extractor_class
    # TODO: add alternative that uses kdu_jp2info
    self.info_extractor_class = ImageMagickInfoExtractor

    # @param input_path [String] The location of an image file
    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

    # @param [Transformation] transformation
    # @param [ImageInformation] image_info
    # @return [String] the processed image data
    def extract(transformation, image_info = info)
      transformer.transform(path, image_info, transformation)
    end

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

    def info
      @info ||= info_extractor.extract
    end

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

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
riiif-2.6.0 app/models/riiif/file.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/riiif-2.5.0/app/models/riiif/file.rb
riiif-2.5.0 app/models/riiif/file.rb
riiif-2.4.0 app/models/riiif/file.rb
riiif-2.3.0 app/models/riiif/file.rb