Module: Imogen::Iiif

Defined in:
lib/imogen/iiif.rb,
lib/imogen/iiif/size.rb,
lib/imogen/iiif/tiles.rb,
lib/imogen/iiif/region.rb,
lib/imogen/iiif/rotation.rb

Defined Under Namespace

Modules: Quality, Tiles Classes: BadRequest, Region, Rotation, Size, Transform

Constant Summary collapse

FORMATS =
{jpeg: 'jpg', jpg: 'jpg', png: 'png', jp2: 'jp2'}
EXTENSIONS =
{'jpg' => :jpeg, 'png' => :png, 'jp2' => :jp2}

Class Method Summary collapse

Class Method Details

.convert(img, dest_path, format = nil, opts = {}) ⇒ Object

Raises:



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/imogen/iiif.rb', line 49

def self.convert(img, dest_path, format=nil, opts={})
  format ||= opts.fetch(:format,:jpeg)
  format = format.to_sym
  raise BadRequest.new("bad format #{format}") unless FORMATS.include? format
  Region.convert(img, opts[:region]) do |region|
    Size.convert(region, opts[:size]) do |size|
      Rotation.convert(size, opts[:rotation]) do |rotation|
        Quality.convert(rotation, opts[:quality]) do |quality|
          quality.write_to_file(dest_path, background: [255, 255, 255])
          yield quality if block_given?
        end
      end
    end
  end
end

.path_to_opts(path, parent_dir) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/imogen/iiif.rb', line 65

def self.path_to_opts(path,parent_dir)
  if parent_dir and path.start_with? parent_dir
    path = path.sub(parent_dir,'')
  end
  path = path[1..-1] if path =~ /^\//
  parts = path.split('/')
  quality = parts[-1].split('.')[0].to_sym
  format = EXTENSIONS[parts[-1].split('.')[1]]
  {
    region: parts[0],
    size: parts[1],
    rotation: parts[2],
    quality: quality,
    format: format
  }
end