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.
26 27 28 29 |
# File 'app/models/riiif/image.rb', line 26 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.
22 23 24 |
# File 'app/models/riiif/image.rb', line 22 def id @id end |
Class Method Details
.cache_key(id, options) ⇒ Object
57 58 59 60 61 |
# File 'app/models/riiif/image.rb', line 57 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. Digest::MD5.hexdigest(str) end |
Instance Method Details
#image ⇒ Object
31 32 33 |
# File 'app/models/riiif/image.rb', line 31 def image @image ||= file_resolver.find(id) end |
#info ⇒ Object
44 45 46 47 48 49 |
# File 'app/models/riiif/image.rb', line 44 def info @info ||= begin result = info_service.call(id, image) ImageInformation.new(result[:width], result[:height]) end end |
#render(args) ⇒ Object
37 38 39 40 41 42 |
# File 'app/models/riiif/image.rb', line 37 def render(args) = (args) Rails.cache.fetch(Image.cache_key(id, ), compress: true, expires_in: Image.expires_in) do image.extract() end end |