Class: Riiif::Image
- Inherits:
-
Object
- Object
- Riiif::Image
- Extended by:
- Deprecation
- Defined in:
- app/models/riiif/image.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
- #file ⇒ Object (also: #image)
- #info ⇒ Object
-
#initialize(id, passed_file = nil) ⇒ Image
constructor
A new instance of Image.
- #render(args) ⇒ Object
Constructor Details
#initialize(id, passed_file = nil) ⇒ Image
Returns a new instance of Image.
43 44 45 46 |
# File 'app/models/riiif/image.rb', line 43 def initialize(id, passed_file = nil) @id = id @file = passed_file if passed_file.present? end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
39 40 41 |
# File 'app/models/riiif/image.rb', line 39 def id @id end |
Class Method Details
.cache_key(id, options) ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'app/models/riiif/image.rb', line 78 def cache_key(id, ) str = .to_h.merge(id: id) .delete_if { |_, v| v.nil? } .sort_by { |k, _v| k.to_s } .to_s # Use a MD5 digest to ensure the keys aren't too long, and a prefix # to avoid collisions with other components in shared cache. 'riiif:' + Digest::MD5.hexdigest(str) end |
.expires_in ⇒ Object
74 75 76 |
# File 'app/models/riiif/image.rb', line 74 def expires_in Riiif::Engine.config.cache_duration_in_days.days end |
Instance Method Details
#file ⇒ Object Also known as: image
48 49 50 |
# File 'app/models/riiif/image.rb', line 48 def file @file ||= file_resolver.find(id) end |
#info ⇒ Object
66 67 68 69 70 71 |
# File 'app/models/riiif/image.rb', line 66 def info @info ||= begin result = info_service.call(id, file) ImageInformation.new(result[:width], result[:height]) end end |
#render(args) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'app/models/riiif/image.rb', line 57 def render(args) cache_opts = args.select { |a| %w(region size quality rotation format).include? a.to_s } key = Image.cache_key(id, cache_opts) cache.fetch(key, compress: true, expires_in: Image.expires_in) do file.extract(OptionDecoder.decode(args, info)) end end |