Class: Riiif::Image
- Inherits:
-
Object
- Object
- Riiif::Image
- Defined in:
- app/models/riiif/image.rb
Constant Summary collapse
- OUTPUT_FORMATS =
%w(jpg png).freeze
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
- #image ⇒ Object
- #info ⇒ Object
-
#initialize(id, file = nil) ⇒ Image
constructor
A new instance of Image.
- #render(args) ⇒ Object
Constructor Details
#initialize(id, file = nil) ⇒ Image
Returns a new instance of Image.
43 44 45 46 |
# File 'app/models/riiif/image.rb', line 43 def initialize(id, file = nil) @id = id @image = file if 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
73 74 75 76 77 78 |
# File 'app/models/riiif/image.rb', line 73 def cache_key(id, ) str = .to_h.merge(id: id).delete_if { |_, v| v.nil? }.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
69 70 71 |
# File 'app/models/riiif/image.rb', line 69 def expires_in Riiif::Engine.config.cache_duration_in_days.days end |
Instance Method Details
#image ⇒ Object
48 49 50 |
# File 'app/models/riiif/image.rb', line 48 def image @image ||= file_resolver.find(id) end |
#info ⇒ Object
61 62 63 64 65 66 |
# File 'app/models/riiif/image.rb', line 61 def info @info ||= begin result = info_service.call(id, image) ImageInformation.new(result[:width], result[:height]) end end |
#render(args) ⇒ Object
54 55 56 57 58 59 |
# File 'app/models/riiif/image.rb', line 54 def render(args) = (args) cache.fetch(Image.cache_key(id, ), compress: true, expires_in: Image.expires_in) do image.extract() end end |