Class: DynamicImage::Metadata
- Inherits:
-
Object
- Object
- DynamicImage::Metadata
- Defined in:
- lib/dynamic_image/metadata.rb
Overview
DynamicImage Metadata
Parses metadata from an image. Expects to receive image data as a binary string.
Instance Method Summary collapse
-
#colorspace ⇒ Object
Returns the color space of the image as a string.
-
#content_type ⇒ Object
Returns the content type of the image.
-
#dimensions ⇒ Object
Returns the dimensions of the image as a vector.
-
#format ⇒ Object
Returns the format of the image.
-
#height ⇒ Object
Returns the height of the image.
-
#initialize(data) ⇒ Metadata
constructor
A new instance of Metadata.
-
#valid? ⇒ Boolean
Returns true if the image is valid.
-
#width ⇒ Object
Returns the width of the image.
Constructor Details
#initialize(data) ⇒ Metadata
Returns a new instance of Metadata.
9 10 11 |
# File 'lib/dynamic_image/metadata.rb', line 9 def initialize(data) @data = data end |
Instance Method Details
#colorspace ⇒ Object
Returns the color space of the image as a string. The result will be one of the following: “rgb”, “cmyk”, “gray”.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/dynamic_image/metadata.rb', line 15 def colorspace return unless valid? case [:colorspace] when /rgb/i "rgb" when /cmyk/i "cmyk" when /gray/i "gray" end end |
#content_type ⇒ Object
Returns the content type of the image.
29 30 31 |
# File 'lib/dynamic_image/metadata.rb', line 29 def content_type "image/#{format.downcase}" if valid? end |
#dimensions ⇒ Object
Returns the dimensions of the image as a vector.
34 35 36 |
# File 'lib/dynamic_image/metadata.rb', line 34 def dimensions Vector2d.new(*[:dimensions]) if valid? end |
#format ⇒ Object
Returns the format of the image.
49 50 51 |
# File 'lib/dynamic_image/metadata.rb', line 49 def format [:format] if valid? end |
#height ⇒ Object
Returns the height of the image.
44 45 46 |
# File 'lib/dynamic_image/metadata.rb', line 44 def height dimensions.try(:y) end |
#valid? ⇒ Boolean
Returns true if the image is valid.
54 55 56 |
# File 'lib/dynamic_image/metadata.rb', line 54 def valid? @data && reader.valid_header? && != :invalid end |
#width ⇒ Object
Returns the width of the image.
39 40 41 |
# File 'lib/dynamic_image/metadata.rb', line 39 def width dimensions.try(:x) end |