Class: WaxIiif::ImageVariant
- Inherits:
-
Object
- Object
- WaxIiif::ImageVariant
- Includes:
- MiniMagick, Utilities::Helpers
- Defined in:
- lib/wax_iiif/image_variant.rb
Overview
Class ImageVariant represents a single image file within a manifest.
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#uri ⇒ String
readonly
The URI for the jpeg image.
Instance Method Summary collapse
-
#generate_image_id(id) ⇒ <type>
Generate a URI for an image.
-
#height ⇒ Number
Get the image height.
-
#initialize(data, config, size = nil) ⇒ ImageVariant
constructor
Initializing an ImageVariant will create the actual image file on the file system.
-
#mime_type ⇒ String
Get the MIME Content-Type of the image.
-
#width ⇒ Number
Get the image width.
Methods included from Utilities::Helpers
#escape_yaml, #generate_build_location, #generate_id, #generate_image_location, #get_data_path, #save_to_disk
Constructor Details
#initialize(data, config, size = nil) ⇒ ImageVariant
Initializing an ImageVariant will create the actual image file on the file system.
To initialize an image, you will need the data hash to have an “id”, a “image_path”, and a “page_number”.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/wax_iiif/image_variant.rb', line 27 def initialize(data, config, size = nil) @config = config raise WaxIiif::Error::InvalidImageData, 'Each image needs an ID' if data.id.nil? || data.id.to_s.empty? raise WaxIiif::Error::InvalidImageData, 'Each image needs an path.' if data.image_path.nil? || data.image_path.to_s.empty? # open image begin @image = Image.open(data.image_path) rescue MiniMagick::Invalid => e raise WaxIiif::Error::InvalidImageData, "Cannot read this image file: #{data.image_path}. #{e}" end width = size.nil? ? width : size resize(width) @image.format 'jpg' @id = generate_image_id(data.id) @uri = "#{id}#{filestring}/default.jpg" # Create the on-disk version of the file path = "#{@id}#{filestring}".gsub(@config.base_url, @config.output_dir) FileUtils.mkdir_p path filename = "#{path}/default.jpg" @image.write filename unless File.exist? filename end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
60 61 62 |
# File 'lib/wax_iiif/image_variant.rb', line 60 def id @id end |
#uri ⇒ String (readonly)
Returns The URI for the jpeg image.
56 57 58 |
# File 'lib/wax_iiif/image_variant.rb', line 56 def uri @uri end |
Instance Method Details
#generate_image_id(id) ⇒ <type>
Generate a URI for an image
91 92 93 |
# File 'lib/wax_iiif/image_variant.rb', line 91 def generate_image_id(id) "#{@config.base_url}#{@config.prefix}/#{@config.image_directory_name}/#{id}" end |
#height ⇒ Number
Get the image height
72 73 74 |
# File 'lib/wax_iiif/image_variant.rb', line 72 def height @image.height end |
#mime_type ⇒ String
Get the MIME Content-Type of the image.
80 81 82 |
# File 'lib/wax_iiif/image_variant.rb', line 80 def mime_type @image.mime_type end |
#width ⇒ Number
Get the image width
65 66 67 |
# File 'lib/wax_iiif/image_variant.rb', line 65 def width @image.width end |